aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJun Wako <wakojun@gmail.com>2015-01-04 17:03:47 +0900
committerJun Wako <wakojun@gmail.com>2015-01-04 17:21:43 +0900
commitd0fefb76f8a1430c749e67bc72b4dba00c7143c9 (patch)
tree2cf2fe560e83fef19c9a99adcc5d2b2300145bfc
parentc6e533ce83d6ae4393e6cdf1f6d39ffefc790115 (diff)
downloadqmk_firmware-d0fefb76f8a1430c749e67bc72b4dba00c7143c9.tar.gz
qmk_firmware-d0fefb76f8a1430c749e67bc72b4dba00c7143c9.zip
infinity: Add initial files for keyboard support
-rw-r--r--README.md2
-rw-r--r--common/matrix.h9
-rw-r--r--common/mbed/xprintf.cpp5
-rw-r--r--keyboard/infinity/MEMO.txt398
-rw-r--r--keyboard/infinity/Makefile6
-rw-r--r--keyboard/infinity/README81
-rw-r--r--keyboard/infinity/keymap.c47
-rw-r--r--keyboard/infinity/keymap_common.c30
-rw-r--r--keyboard/infinity/keymap_common.h58
-rw-r--r--keyboard/infinity/led.c25
-rw-r--r--keyboard/infinity/main.cpp38
-rw-r--r--keyboard/infinity/matrix.c107
-rw-r--r--keyboard/infinity/mbed-infinity.mk2
-rw-r--r--keyboard/infinity/mbed-infinity/README39
-rw-r--r--keyboard/infinity/mbed-infinity/USBHAL_KL25Z.cpp557
-rw-r--r--keyboard/infinity/tool/README25
-rw-r--r--tool/mbed/lpc11u35_501.mk1
-rw-r--r--tool/mbed/mbed.mk10
18 files changed, 1029 insertions, 411 deletions
diff --git a/README.md b/README.md
index a01de8c6f..e077fc928 100644
--- a/README.md
+++ b/README.md
@@ -53,6 +53,7 @@ You can find some keyboard specific projects under `converter` and `keyboard` di
53* [macway](keyboard/macway/) - [Compact keyboard mod][GH_macway] [retired] 53* [macway](keyboard/macway/) - [Compact keyboard mod][GH_macway] [retired]
54* [KMAC](keyboard/kmac/) - Korean custom keyboard 54* [KMAC](keyboard/kmac/) - Korean custom keyboard
55* [Lightsaber](keyboard/lightsaber/) - Korean custom keyboard 55* [Lightsaber](keyboard/lightsaber/) - Korean custom keyboard
56* [Infinity](keyboard/infinity/) - Massdrop [Infinity keyboard][Infinity]
56 57
57[GH_macway]: http://geekhack.org/showwiki.php?title=Island:11930 58[GH_macway]: http://geekhack.org/showwiki.php?title=Island:11930
58[GH_hhkb]: http://geekhack.org/showwiki.php?title=Island:12047 59[GH_hhkb]: http://geekhack.org/showwiki.php?title=Island:12047
@@ -72,6 +73,7 @@ You can find some keyboard specific projects under `converter` and `keyboard` di
72[PC98]: http://en.wikipedia.org/wiki/NEC_PC-9801 73[PC98]: http://en.wikipedia.org/wiki/NEC_PC-9801
73[Sun]: http://en.wikipedia.org/wiki/Sun-3 74[Sun]: http://en.wikipedia.org/wiki/Sun-3
74[IIGS]: http://en.wikipedia.org/wiki/Apple_IIGS 75[IIGS]: http://en.wikipedia.org/wiki/Apple_IIGS
76[Infinity]: https://www.massdrop.com/buy/infinity-keyboard-kit
75 77
76 78
77 79
diff --git a/common/matrix.h b/common/matrix.h
index 23fef78f7..107ee7265 100644
--- a/common/matrix.h
+++ b/common/matrix.h
@@ -35,6 +35,10 @@ typedef uint32_t matrix_row_t;
35#define MATRIX_IS_ON(row, col) (matrix_get_row(row) && (1<<col)) 35#define MATRIX_IS_ON(row, col) (matrix_get_row(row) && (1<<col))
36 36
37 37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
38/* number of matrix rows */ 42/* number of matrix rows */
39uint8_t matrix_rows(void); 43uint8_t matrix_rows(void);
40/* number of matrix columns */ 44/* number of matrix columns */
@@ -48,7 +52,7 @@ bool matrix_is_modified(void) __attribute__ ((deprecated));
48/* whether a swtich is on */ 52/* whether a swtich is on */
49bool matrix_is_on(uint8_t row, uint8_t col); 53bool matrix_is_on(uint8_t row, uint8_t col);
50/* matrix state on row */ 54/* matrix state on row */
51matrix_row_t matrix_get_row(uint8_t row); 55matrix_row_t matrix_get_row(uint8_t row);
52/* print matrix for debug */ 56/* print matrix for debug */
53void matrix_print(void); 57void matrix_print(void);
54 58
@@ -57,5 +61,8 @@ void matrix_print(void);
57void matrix_power_up(void); 61void matrix_power_up(void);
58void matrix_power_down(void); 62void matrix_power_down(void);
59 63
64#ifdef __cplusplus
65}
66#endif
60 67
61#endif 68#endif
diff --git a/common/mbed/xprintf.cpp b/common/mbed/xprintf.cpp
index 4342b79f8..3647ece75 100644
--- a/common/mbed/xprintf.cpp
+++ b/common/mbed/xprintf.cpp
@@ -6,6 +6,10 @@
6 6
7#define STRING_STACK_LIMIT 120 7#define STRING_STACK_LIMIT 120
8 8
9//TODO
10int xprintf(const char* format, ...) { return 0; }
11
12#if 0
9/* mbed Serial */ 13/* mbed Serial */
10Serial ser(UART_TX, UART_RX); 14Serial ser(UART_TX, UART_RX);
11 15
@@ -44,3 +48,4 @@ int xprintf(const char* format, ...)
44 return r; 48 return r;
45*/ 49*/
46} 50}
51#endif
diff --git a/keyboard/infinity/MEMO.txt b/keyboard/infinity/MEMO.txt
deleted file mode 100644
index ca0da937d..000000000
--- a/keyboard/infinity/MEMO.txt
+++ /dev/null
@@ -1,398 +0,0 @@
1mbed patch for Infinity
2-----------------------
3Without ld script patch vector table it doesn't place vector table in binary file.
4And clock setting is changed as Infinity uses internal oscillator instead of exteranl crystal.
5
6diff --git a/libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D50M/TOOLCHAIN_GCC_ARM/MK20D5.ld b/libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D50M/TOOLCHAIN_GCC_ARM/MK20D5.ld
7index 600751c..55c3393 100644
8--- a/libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D50M/TOOLCHAIN_GCC_ARM/MK20D5.ld
9+++ b/libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D50M/TOOLCHAIN_GCC_ARM/MK20D5.ld
10@@ -43,7 +43,7 @@ SECTIONS
11 .isr_vector :
12 {
13 __vector_table = .;
14- KEEP(*(.vector_table))
15+ KEEP(*(.isr_vector))
16 *(.text.Reset_Handler)
17 *(.text.System_Init)
18 . = ALIGN(4);
19diff --git a/libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D50M/system_MK20D5.c b/libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D50M/system_MK20D5.c
20index 393d1f0..b78b71a 100644
21--- a/libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D50M/system_MK20D5.c
22+++ b/libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D50M/system_MK20D5.c
23@@ -44,7 +44,7 @@
24
25 #define DISABLE_WDOG 1
26
27-#define CLOCK_SETUP 1
28+#define CLOCK_SETUP 0
29 /* Predefined clock setups
30 0 ... Multipurpose Clock Generator (MCG) in FLL Engaged Internal (FEI) mode
31 Reference clock source for MCG module is the slow internal clock source 32.768kHz
32
33
34
35CMSIS/mbed HAL
36==============
37http://developer.mbed.org/users/MACRUM/notebook/mbed-library-internals/
38
39api/ mbed API
40├── AnalogIn.h
41├── AnalogOut.h
42├── BusIn.h
43├── BusInOut.h
44├── BusOut.h
45├── CallChain.h
46├── CAN.h
47├── can_helper.h
48├── DigitalIn.h
49├── DigitalInOut.h
50├── DigitalOut.h
51├── DirHandle.h
52├── Ethernet.h
53├── FileBase.h
54├── FileHandle.h
55├── FileLike.h
56├── FilePath.h
57├── FileSystemLike.h
58├── FunctionPointer.h
59├── I2C.h
60├── I2CSlave.h
61├── InterruptIn.h
62├── InterruptManager.h
63├── LocalFileSystem.h
64├── mbed_assert.h
65├── mbed_debug.h
66├── mbed_error.h
67├── mbed.h
68├── mbed_interface.h
69├── platform.h
70├── PortIn.h
71├── PortInOut.h
72├── PortOut.h
73├── PwmOut.h
74├── RawSerial.h
75├── rtc_time.h
76├── semihost_api.h
77├── SerialBase.h
78├── Serial.h
79├── SPI.h
80├── SPISlave.h
81├── Stream.h
82├── Ticker.h
83├── Timeout.h
84├── TimerEvent.h
85├── Timer.h
86├── toolchain.h
87└── wait_api.h
88
89common/ mbed API implementation
90
91hal/ mbed HAL implementation interface
92├── analogin_api.h
93├── analogout_api.h
94├── can_api.h
95├── ethernet_api.h
96├── gpio_api.h
97├── gpio_irq_api.h
98├── i2c_api.h
99├── pinmap.h
100├── port_api.h
101├── pwmout_api.h
102├── rtc_api.h
103├── serial_api.h
104├── sleep_api.h
105├── spi_api.h
106└── us_ticker_api.h
107
108targets/hal/TARGET_<vendor>/TARGET_<board>/
109 mbed HAL implementation
110
111targets/cmsis/ CMSIS interface
112 core_caInstr.h
113 core_ca9.h
114 core_cmFunc.h
115 core_caFunc.h
116 core_cmInstr.h
117 core_cm4_simd.h
118 core_ca_mmu.h
119 core_cm0.h
120 core_cm0plus.h
121 core_cm3.h
122 core_cm4.h
123
124targets/cmsis/TARGET_<vendor>/TARGET_<chip>/
125 <chip>.h
126 system_<chip>.[ch]
127 cmsis.h 
128 cmsis_nvic.[ch]
129
130targets/cmsis/TARGET_<vendor>/TARGET_<chip>/TOOLSCHAIN_<tool>/
131 startup_<chip>.s
132 linker-script
133
134
135
136Infinity
137========
138Massdrop Infinity Keyboard:
139https://www.massdrop.com/buy/infinity-keyboard-kit
140
141Freescale MK20DX128VLF5 48-QFP:
142http://cache.freescale.com/files/32bit/doc/data_sheet/K20P48M50SF0.pdf
143
144kiibohd controller(MD1):
145https://github.com/kiibohd/controller
146
147DFU bootloader:
148https://github.com/kiibohd/controller/tree/master/Bootloader
149
150Program with bootloader:
151 $ dfu-util -D kiibohd.dfu.bin
152
153Pinout:
154https://github.com/kiibohd/controller/blob/master/Scan/MD1/pinout
155
156
157
158Pin Usage
159=========
160
161mk20dx128vlf5
162
163 ----
164|Keys|
165 ----
166
167* Strobe (Columns)
168
169PTB0
170PTB1
171PTB2
172PTB3
173PTB16
174PTB17
175PTC4
176PTC5
177PTD0
178
179
180* Sense (Rows)
181
182PTD1
183PTD2
184PTD3
185PTD4
186PTD5
187PTD6
188PTD7
189
190
191 -----
192|Debug|
193 -----
194
195* SWD
196
197PTA0 (Pull-down)
198PTA3 (Pull-up)
199
200* LEDs
201
202PTA19 (LED only for PCB, not McHCK) (XTAL)
203
204* UARTs
205
206PTA1 - RX0
207PTA2 - TX0
208
209
210 ------
211|Unused|
212 ------
213
214* GPIO
215
216PTA1 (Not broken out on PCB, available on McHCK) (Pull-up)
217PTA2 (")
218PTA4 (Pull-up)
219PTA18 (EXTAL)
220
221PTC0
222PTC1
223PTC2
224PTC3
225PTC6
226PTC7
227
228* Analog
229
230ADC0_DP0
231ADC0_DM0
232
233
234
235Freescale kinetis MK20DX128
236===========================
237If FSEC of flash config at 0x400-40F is changed accidentally SWD/JTAG debug access will be lost and very difficult to get back.
238For example, high level adapter like stlink cannot work to get access back after FSEC is changed. To regain the chip to be programmable low level DAP inteface like JTAG, CMSIS-DAP or OpenSAD.
239
240
241Memory map
242==========
243kiibohd bootloader: Lib/mk20dx128vlf5.bootloader.ld
2440x0000_0000 +-------------------+ -----------------+---------------+
245 | .vectors | ---------. | StackPointer0 |
246 | .startup | \ | ResetHandler1 |
247 | .rodata | \ | ... |
2480x0000_0400 | .flashconfig | 0x10 \ | ... |
249 | .text | \ | ... 61 | 0xF7
250 | .init | `--+---------------+ 0xF8
2510x0000_1000 +-------------------+ 4KB
252 | _app_rom |
253 ~ ~
254 ~ ~
255 | |
2560x07FF_FFFF +-------------------+ 128KB
257
258
2590x1FFF_E000 +-------------------+
260 | |
261 | RAM |
262 | 8KB|
2630x2000_0000 +-------------------+
264 | |
265 | RAM |
266 | 8KB|
2670x2000_2000 +-------------------+ _estack
268
269
270
271
272
273OpenOCD
274========
275Synopsis of SWD, JTAG and SWJ-DP transport:
276https://fedcsis.org/proceedings/2012/pliks/279.pdf
277
278OpenSDA Freescale: Mass storage bootloader & serial port; part of CMSIS-DAP?
279http://cache.freescale.com/files/32bit/doc/user_guide/OPENSDAUG.pdf
280
281
282interface_list:
283 1: ftdi
284 2: usb_blaster
285 3: usbprog
286 4: jlink
287 5: vsllink
288 6: rlink
289 7: ulink
290 8: arm-jtag-ew
291 9: hla
292 10: osbdm
293 11: opendous
294 12: aice
295 13: cmsis-dap
296
297transport list:
298 stlink_swim
299 hla_jtag
300 hla_swd
301 aice_jtag
302 swd
303 cmsis-dap
304 jtag
305
306target types:
307 arm7tdmi
308 arm9tdmi
309 arm920t
310 arm720t
311 arm966e
312 arm946e
313 arm926ejs
314 fa526
315 feroceon
316 dragonite
317 xscale
318 cortex_m
319 cortex_a
320 cortex_r4
321 arm11
322 mips_m4k
323 avr
324 dsp563xx
325 dsp5680xx
326 testee
327 avr32_ap7k
328 hla_target
329 nds32_v2
330 nds32_v3
331 nds32_v3m
332 or1k
333 quark_x10xx
334
335
336TAP
337---
338http://openocd.sourceforge.net/doc/html/TAP-Declaration.html#TAP-Declaration
339 jtag newtap chipname tapname configparams...
340 hla newtap chipname tapname configparams...
341 swd newtap chipname tapname configparams...
342 cmsis-dap newtap chipname tapname configparams...
343
344 The tapname reflects the role of that TAP, and should follow this convention:
345 bs – For boundary scan if this is a separate TAP;
346 cpu – The main CPU of the chip, alternatively arm and dsp on chips with both ARM and DSP CPUs, arm1 and arm2 on chips with two ARMs, and so forth;
347 etb – For an embedded trace buffer (example: an ARM ETB11);
348 flash – If the chip has a flash TAP, like the str912;
349 jrc – For JTAG route controller (example: the ICEPick modules on many Texas Instruments chips, like the OMAP3530 on Beagleboards);
350 tap – Should be used only for FPGA- or CPLD-like devices with a single TAP;
351 unknownN – If you have no idea what the TAP is for (N is a number);
352 when in doubt – Use the chip maker's name in their data sheet. For example, the Freescale i.MX31 has a SDMA (Smart DMA) with a JTAG TAP; that TAP should be named sdma.
353
354-irlen NUMBER
355The length in bits of the instruction register, such as 4 or 5 bits.
356
357Target
358------
359http://openocd.sourceforge.net/doc/html/CPU-Configuration.html#CPU-Configuration
360
361 target create target_name type configparams...
362 $target_name configure configparams...
363
364 -chain-position dotted.name – names the TAP used to access this target.
365 -endian (big|little) – specifies whether the CPU uses big or little endian conventions
366 -event event_name event_body – See Target Events. Note that this updates a list of named event handlers. Calling this twice with two different event names assigns two different handlers, but calling it twice with the same event name assigns only one handler.
367 -work-area-backup (0|1) – says whether the work area gets backed up; by default, it is not backed up. When possible, use a working_area that doesn't need to be backed up, since performing a backup slows down operations. For example, the beginning of an SRAM block is likely to be used by most build systems, but the end is often unused.
368 -work-area-size size – specify work are size, in bytes. The same size applies regardless of whether its physical or virtual address is being used.
369 -work-area-phys address – set the work area base address to be used when no MMU is active.
370 -work-area-virt address – set the work area base address to be used when an MMU is active. Do not specify a value for this except on targets with an MMU. The value should normally correspond to a static mapping for the -work-area-phys address, set up by the current operating system.
371 -rtos rtos_type – enable rtos support for target, rtos_type can be one of auto|eCos|ThreadX| FreeRTOS|linux|ChibiOS|embKernel See RTOS Support.
372
373Flash
374-----
375http://openocd.sourceforge.net/doc/html/Flash-Commands.html#norconfiguration
376
377 flash bank name driver base size chip_width bus_width target [driver_options]
378
379 name ... may be used to reference the flash bank in other flash commands. A number is also available.
380 driver ... identifies the controller driver associated with the flash bank being declared. This is usually cfi for external flash, or else the name of a microcontroller with embedded flash memory. See Flash Driver List.
381 base ... Base address of the flash chip.
382 size ... Size of the chip, in bytes. For some drivers, this value is detected from the hardware.
383 chip_width ... Width of the flash chip, in bytes; ignored for most microcontroller drivers.
384 bus_width ... Width of the data bus used to access the chip, in bytes; ignored for most microcontroller drivers.
385 target ... Names the target used to issue commands to the flash controller.
386 driver_options ... drivers may support, or require, additional parameters. See the driver-specific documentation for more information.
387
388 flash write_image [erase] [unlock] filename [offset] [type]
389
390
391Memory Access
392-------------
393http://openocd.sourceforge.net/doc/html/General-Commands.html#imageaccess
394 {mdw,mdh,mdb} addr [count]
395 dump {word, half-word, byte} data
396 {mww,mwh,mwb} addr data
397 write data
398
diff --git a/keyboard/infinity/Makefile b/keyboard/infinity/Makefile
index e97f759df..758296f33 100644
--- a/keyboard/infinity/Makefile
+++ b/keyboard/infinity/Makefile
@@ -11,6 +11,10 @@ vpath %.cpp .:$(MBED_DIR):$(TMK_DIR)
11OBJDIR = ./build 11OBJDIR = ./build
12 12
13OBJECTS = \ 13OBJECTS = \
14 $(OBJDIR)/matrix.o \
15 $(OBJDIR)/keymap.o \
16 $(OBJDIR)/keymap_common.o \
17 $(OBJDIR)/led.o \
14 $(OBJDIR)/main.o 18 $(OBJDIR)/main.o
15 19
16CONFIG_H = config.h 20CONFIG_H = config.h
@@ -29,5 +33,5 @@ include $(TMK_DIR)/tool/mbed/mbed.mk
29include $(TMK_DIR)/tool/mbed/common.mk 33include $(TMK_DIR)/tool/mbed/common.mk
30include $(TMK_DIR)/tool/mbed/gcc.mk 34include $(TMK_DIR)/tool/mbed/gcc.mk
31 35
32program: 36program: $(OBJDIR)/$(PROJECT).bin
33 dfu-util -D $(OBJDIR)/$(PROJECT).bin 37 dfu-util -D $(OBJDIR)/$(PROJECT).bin
diff --git a/keyboard/infinity/README b/keyboard/infinity/README
new file mode 100644
index 000000000..53d1c9173
--- /dev/null
+++ b/keyboard/infinity/README
@@ -0,0 +1,81 @@
1Infinity
2========
3Massdrop Infinity Keyboard:
4https://www.massdrop.com/buy/infinity-keyboard-kit
5
6kiibohd controller(MD1):
7https://github.com/kiibohd/controller
8
9DFU bootloader:
10https://github.com/kiibohd/controller/tree/master/Bootloader
11
12Program with bootloader:
13 $ dfu-util -D kiibohd.dfu.bin
14
15Pinout:
16https://github.com/kiibohd/controller/blob/master/Scan/MD1/pinout
17
18MCHCK compatible:
19https://mchck.org/about/
20
21MCU Freescale MK20DX128VLF5 48-QFP:
22http://cache.freescale.com/files/32bit/doc/data_sheet/K20P48M50SF0.pdf
23
24
25
26Pin Usage
27=========
28Key Matrix:
29 Strobe(output high): PTB0 PTB1 PTB2 PTB3 PTB16 PTB17 PTC4 PTC5 PTD0
30 Sense(input with pull-down): PTD1 PTD2 PTD3 PTD4 PTD5 PTD6 PTD7
31
32
33SWD pinout:
34 SWD_CLK(PTA0) SWD_DIO(PTA3)
35 SWD pins are placed next to reset button; SWD_CLK, SWD_DIO, GND, VCC from top.
36 Note that RESET is also needed to get full control with OpenOCD.
37
38LED:
39 PTA19(turns on with output high)
40
41
42
43Memory map
44==========
45kiibohd bootloader: Lib/mk20dx128vlf5.bootloader.ld
460x0000_0000 +-------------------+ -----------------+---------------+ Vector table
47 | .vectors | ------------. | StackPointer0 | of Bootloader
48 | .startup | \ | ResetHandler1 |
49 | .rodata | `--+---------------+ 0xF8
500x0000_0400 | .flashconfig(0x10)|
51 _0410 | .text |
52 | .init |
530x0000_1000 +-------------------+ -----------------+---------------+ Vector table
54 | _app_rom | ------------. | | of App
55 | | \ | |
56 | | `--+---------------+
57 | |
58 ~ ~
59 | |
600x07FF_FFFF +-------------------+ 128KB
61
62
630x1FFF_E000 +-------------------+ -----------------+---------------+ Vector table
64 _E0F8 | | ------------. | | of App(copied)
65 | | \ | |
66 | | `--+---------------+ mbed NVIC
67 | |
68 | RAM |
69 | 8KB|
700x2000_0000 +-------------------+
71 | |
72 | |
73 | |
74 | |
75 | RAM |
76 | 8KB|
770x2000_2000 +-------------------+ _estack
78
79
80
81
diff --git a/keyboard/infinity/keymap.c b/keyboard/infinity/keymap.c
new file mode 100644
index 000000000..100142f41
--- /dev/null
+++ b/keyboard/infinity/keymap.c
@@ -0,0 +1,47 @@
1#include "keymap_common.h"
2
3const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
4 /* Layer 0: Default Layer
5 * ,-----------------------------------------------------------.
6 * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| `|BSp|
7 * |-----------------------------------------------------------|
8 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \|
9 * |-----------------------------------------------------------|
10 * |Contro| A| S| D| F| G| H| J| K| L| ;| '|Enter |
11 * |-----------------------------------------------------------|
12 * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn0|
13 * |-----------------------------------------------------------'
14 * | |Gui|Alt | Space |Alt |Gui| | |
15 * `-----------------------------------------------------------'
16 */
17 [0] =
18 KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS, GRV, \
19 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \
20 LCTL,A, S, D, F, G, H, J, K, L, SCLN,QUOT,ENT, \
21 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH,RSFT,FN0, \
22 NO, LGUI,LALT, SPC, RALT,RGUI,NO, NO),
23 /* Layer 1: HHKB mode (HHKB Fn)
24 * ,-----------------------------------------------------------.
25 * |Pwr| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
26 * |-----------------------------------------------------------|
27 * |Caps | | | | | | | |Psc|Slk|Pus|Up | |Backs|
28 * |-----------------------------------------------------------|
29 * | |VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter |
30 * |-----------------------------------------------------------|
31 * | | | | | | | +| -|End|PgD|Dow| | |
32 * `-----------------------------------------------------------'
33 * | |Gui|Alt | Space |Alt |Gui| | |
34 * `-----------------------------------------------------------'
35 */
36 [1]=
37 KEYMAP(PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
38 CAPS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,SLCK,PAUS, UP, TRNS, BSPC, \
39 TRNS,VOLD,VOLU,MUTE,TRNS,TRNS,PAST,PSLS,HOME,PGUP,LEFT,RGHT,PENT, \
40 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PPLS,PMNS,END, PGDN,DOWN,TRNS,TRNS, \
41 TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS),
42};
43
44const uint16_t PROGMEM fn_actions[] = {
45 [0] = ACTION_LAYER_MOMENTARY(1),
46};
47
diff --git a/keyboard/infinity/keymap_common.c b/keyboard/infinity/keymap_common.c
new file mode 100644
index 000000000..fdb1769e1
--- /dev/null
+++ b/keyboard/infinity/keymap_common.c
@@ -0,0 +1,30 @@
1/*
2Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#include "keymap_common.h"
18
19
20/* translates key to keycode */
21uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
22{
23 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
24}
25
26/* translates Fn keycode to action */
27action_t keymap_fn_to_action(uint8_t keycode)
28{
29 return (action_t){ .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) };
30}
diff --git a/keyboard/infinity/keymap_common.h b/keyboard/infinity/keymap_common.h
new file mode 100644
index 000000000..7a5f778f2
--- /dev/null
+++ b/keyboard/infinity/keymap_common.h
@@ -0,0 +1,58 @@
1/*
2Copyright 2014 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#ifndef KEYMAP_COMMON_H
18#define KEYMAP_COMMON_H
19
20#include <stdint.h>
21#include <stdbool.h>
22#include "keycode.h"
23#include "action.h"
24#include "action_macro.h"
25#include "report.h"
26#include "host.h"
27#include "print.h"
28#include "debug.h"
29#include "keymap.h"
30
31
32extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
33extern const uint16_t fn_actions[];
34
35
36/* GH60 keymap definition macro
37 * K2C, K31 and K3C are extra keys for ISO
38 */
39#define KEYMAP( \
40 K00, K10, K20, K30, K40, K50, K60, K70, K80, K01, K11, K21, K31, K41, K86, \
41 K51, K61, K71, K81, K02, K12, K22, K32, K42, K52, K62, K72, K82, K03, \
42 K13, K23, K33, K43, K53, K63, K73, K83, K04, K14, K24, K34, K44, \
43 K54, K64, K74, K84, K05, K15, K25, K35, K45, K55, K65, K75, K85, \
44 K06, K16, K26, K36, K46, K56, K66, K76 \
45) { \
46 { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06 }, \
47 { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16 }, \
48 { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26 }, \
49 { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36 }, \
50 { KC_##K40, KC_##K41, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46 }, \
51 { KC_##K50, KC_##K51, KC_##K52, KC_##K53, KC_##K54, KC_##K55, KC_##K56 }, \
52 { KC_##K60, KC_##K61, KC_##K62, KC_##K63, KC_##K64, KC_##K65, KC_##K66 }, \
53 { KC_##K70, KC_##K71, KC_##K72, KC_##K73, KC_##K74, KC_##K75, KC_##K76 }, \
54 { KC_##K80, KC_##K81, KC_##K82, KC_##K83, KC_##K84, KC_##K85, KC_##K86 } \
55}
56
57#endif
58
diff --git a/keyboard/infinity/led.c b/keyboard/infinity/led.c
new file mode 100644
index 000000000..b7e638b25
--- /dev/null
+++ b/keyboard/infinity/led.c
@@ -0,0 +1,25 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "stdint.h"
19#include "led.h"
20
21
22/* HHKB has no LEDs */
23void led_set(uint8_t usb_led)
24{
25}
diff --git a/keyboard/infinity/main.cpp b/keyboard/infinity/main.cpp
index f28840d3e..847668a1d 100644
--- a/keyboard/infinity/main.cpp
+++ b/keyboard/infinity/main.cpp
@@ -1,20 +1,44 @@
1//#include "mbed.h"
2#include "MK20D5.h" 1#include "MK20D5.h"
3#include "wait.h" 2#include "wait.h"
4#include "gpio_api.h" 3#include "gpio_api.h"
5#include "PinNames.h" 4#include "PinNames.h"
5#include "matrix.h"
6#include "timer.h"
7
8#include "action.h"
9#include "keycode.h"
10#include "host.h"
11#include "host_driver.h"
12#include "mbed_driver.h"
6 13
7 14
8int main() { 15int main() {
9 gpio_t led; 16 gpio_t led;
10 gpio_init_out(&led, PTA19); 17 gpio_init_out(&led, PTA19);
18
19 uint16_t t = 0;
20
21 host_set_driver(&mbed_driver);
22 keyboard_init();
23
11 while(1) { 24 while(1) {
12 wait_ms(500); 25 keyboard_task();
13 uint32_t delay = 0xf; 26
14 while (delay--) { 27 bool matrix_on = false;
15 uint32_t delay2 = 0xffff; 28 matrix_scan();
16 while (delay2--) ; 29 for (int i = 0; i < MATRIX_ROWS; i++) {
30 if (matrix_get_row(i)) {
31 matrix_on = true;
32 break;
33 }
34 }
35 if (matrix_on)
36 gpio_write(&led, 1);
37 else {
38 if (timer_elapsed(t) > 500) {
39 gpio_write(&led, !gpio_read(&led));
40 t = timer_read();
41 }
17 } 42 }
18 gpio_write(&led, !gpio_read(&led));
19 } 43 }
20} 44}
diff --git a/keyboard/infinity/matrix.c b/keyboard/infinity/matrix.c
new file mode 100644
index 000000000..478a40fd9
--- /dev/null
+++ b/keyboard/infinity/matrix.c
@@ -0,0 +1,107 @@
1#include <stdint.h>
2#include <stdbool.h>
3#include "gpio_api.h"
4#include "timer.h"
5#include "wait.h"
6#include "matrix.h"
7
8
9#ifndef DEBOUNCE
10#define DEBOUNCE 5
11#endif
12
13/*
14 * Infinity Pinusage:
15 * Column pins are input with internal pull-down. Row pins are output and strobe with high.
16 * Key is high or 1 when it turns on.
17 *
18 * col: { PTD1, PTD2, PTD3, PTD4, PTD5, PTD6, PTD7 }
19 * row: { PTB0, PTB1, PTB2, PTB3, PTB16, PTB17, PTC4, PTC5, PTD0 }
20 */
21static gpio_t col[MATRIX_COLS];
22static gpio_t row[MATRIX_ROWS];
23
24/* matrix state(1:on, 0:off) */
25static matrix_row_t matrix[MATRIX_ROWS];
26static matrix_row_t matrix_debouncing[MATRIX_ROWS];
27static bool debouncing = false;
28static uint16_t debouncing_time = 0;
29
30
31void matrix_init(void)
32{
33 /* Column(sense) */
34 gpio_init_in_ex(&col[0], PTD1, PullDown);
35 gpio_init_in_ex(&col[1], PTD2, PullDown);
36 gpio_init_in_ex(&col[2], PTD3, PullDown);
37 gpio_init_in_ex(&col[3], PTD4, PullDown);
38 gpio_init_in_ex(&col[4], PTD5, PullDown);
39 gpio_init_in_ex(&col[5], PTD6, PullDown);
40 gpio_init_in_ex(&col[6], PTD7, PullDown);
41
42 /* Row(strobe) */
43 gpio_init_out_ex(&row[0], PTB0, 0);
44 gpio_init_out_ex(&row[1], PTB1, 0);
45 gpio_init_out_ex(&row[2], PTB2, 0);
46 gpio_init_out_ex(&row[3], PTB3, 0);
47 gpio_init_out_ex(&row[4], PTB16, 0);
48 gpio_init_out_ex(&row[5], PTB17, 0);
49 gpio_init_out_ex(&row[6], PTC4, 0);
50 gpio_init_out_ex(&row[7], PTC5, 0);
51 gpio_init_out_ex(&row[8], PTD0, 0);
52}
53
54uint8_t matrix_scan(void)
55{
56 for (int i = 0; i < MATRIX_ROWS; i++) {
57 matrix_row_t r = 0;
58
59 gpio_write(&row[i], 1);
60 wait_us(1); // need wait to settle pin state
61 for (int j = 0; j < MATRIX_COLS; j++) {
62 if (gpio_read(&col[j])) {
63 r |= (1<<j);
64 }
65 }
66 gpio_write(&row[i], 0);
67
68 if (matrix_debouncing[i] != r) {
69 matrix_debouncing[i] = r;
70 debouncing = true;
71 debouncing_time = timer_read();
72 }
73 }
74
75 if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) {
76 for (int i = 0; i < MATRIX_ROWS; i++) {
77 matrix[i] = matrix_debouncing[i];
78 }
79 debouncing = false;
80 }
81/*
82 if (debouncing) {
83 if (--debouncing) {
84 return 0;
85 } else {
86 for (int i = 0; i < MATRIX_ROWS; i++) {
87 matrix[i] = matrix_debouncing[i];
88 }
89 }
90 }
91*/
92 return 1;
93}
94
95bool matrix_is_on(uint8_t row, uint8_t col)
96{
97 return (matrix[row] & (1<<col));
98}
99
100matrix_row_t matrix_get_row(uint8_t row)
101{
102 return matrix[row];
103}
104
105void matrix_print(void)
106{
107}
diff --git a/keyboard/infinity/mbed-infinity.mk b/keyboard/infinity/mbed-infinity.mk
index cd4434a23..f5fd2c997 100644
--- a/keyboard/infinity/mbed-infinity.mk
+++ b/keyboard/infinity/mbed-infinity.mk
@@ -4,6 +4,7 @@
4CPU = -mcpu=cortex-m4 -mthumb 4CPU = -mcpu=cortex-m4 -mthumb
5 5
6CC_SYMBOLS += \ 6CC_SYMBOLS += \
7 -DTARGET_INFINITY \
7 -DTARGET_K20D50M \ 8 -DTARGET_K20D50M \
8 -DTARGET_M4 \ 9 -DTARGET_M4 \
9 -DTARGET_CORTEX_M \ 10 -DTARGET_CORTEX_M \
@@ -17,6 +18,7 @@ CC_SYMBOLS += \
17OBJECTS += \ 18OBJECTS += \
18 $(OBJDIR)/mbed-infinity/cmsis_nvic.o \ 19 $(OBJDIR)/mbed-infinity/cmsis_nvic.o \
19 $(OBJDIR)/mbed-infinity/system_MK20D5.o \ 20 $(OBJDIR)/mbed-infinity/system_MK20D5.o \
21 $(OBJDIR)/mbed-infinity/USBHAL_KL25Z.o \
20 $(OBJDIR)/libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D50M/TOOLCHAIN_GCC_ARM/startup_MK20D5.o \ 22 $(OBJDIR)/libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D50M/TOOLCHAIN_GCC_ARM/startup_MK20D5.o \
21 $(OBJDIR)/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D50M/analogin_api.o \ 23 $(OBJDIR)/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D50M/analogin_api.o \
22 $(OBJDIR)/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D50M/gpio_api.o \ 24 $(OBJDIR)/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_K20D50M/gpio_api.o \
diff --git a/keyboard/infinity/mbed-infinity/README b/keyboard/infinity/mbed-infinity/README
new file mode 100644
index 000000000..b0d226f79
--- /dev/null
+++ b/keyboard/infinity/mbed-infinity/README
@@ -0,0 +1,39 @@
1mbed fix for Infinity
2=====================
3Without linker script patch it doesn't place vector table in final binary.
4And clock is configured to 48MHz using internal clock reference and FLL multiplication.
5
6
7mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D50M/system_MK20D5.c
8 Fix SystemInit: clock setup for internal clock. Inifinity has no external Xtal.
9
10mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D50M/cmsis_nvic.c
11 Fix NVIC vector address of firmware 0x1000 instead of 0x0
12
13mbed/targets/cmsis/TARGET_Freescale/TARGET_K20D50M/TOOLCHAIN_GCC_ARM/MK20D5.ld
14 Fix memory map for Infinity bootloader
15 Flash starts at 0x1000
16 No flash config bytes sector
17
18USBDevice/USBDevice/USBHAL_KL25Z.cpp
19 Fix USB clock setup, see below.
20
21
222015/01/04 Based on mbed-sdk @2f63fa7d78a26.
23
24
25
26Kinetis USB config
27==================
28Clock source: Internal reference clock wth FLL
29 SIM_SOPT[USBSRC] = 1(MCGPLLCLK/MCGFLLCLK)
30 SIM_SOPT[PLLSEL] = 0(MCGFLLCLK)
31
32Clock dividor:
33 SIM_CLKDIV2[USBDIV] = 0
34 SIM_CLKDIV2[USBFAC] = 0
35
36Clock enable:
37 SIM_SCGC4[USBOTG] = 1
38
39
diff --git a/keyboard/infinity/mbed-infinity/USBHAL_KL25Z.cpp b/keyboard/infinity/mbed-infinity/USBHAL_KL25Z.cpp
new file mode 100644
index 000000000..90f02fa32
--- /dev/null
+++ b/keyboard/infinity/mbed-infinity/USBHAL_KL25Z.cpp
@@ -0,0 +1,557 @@
1/* Copyright (c) 2010-2011 mbed.org, MIT License
2*
3* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4* and associated documentation files (the "Software"), to deal in the Software without
5* restriction, including without limitation the rights to use, copy, modify, merge, publish,
6* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
7* Software is furnished to do so, subject to the following conditions:
8*
9* The above copyright notice and this permission notice shall be included in all copies or
10* substantial portions of the Software.
11*
12* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
13* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17*/
18
19#if defined(TARGET_KL25Z) | defined(TARGET_KL43Z) | defined(TARGET_KL46Z) | defined(TARGET_K20D50M) | defined(TARGET_K64F) | defined(TARGET_K22F)
20
21#include "USBHAL.h"
22
23USBHAL * USBHAL::instance;
24
25static volatile int epComplete = 0;
26
27// Convert physical endpoint number to register bit
28#define EP(endpoint) (1<<(endpoint))
29
30// Convert physical to logical
31#define PHY_TO_LOG(endpoint) ((endpoint)>>1)
32
33// Get endpoint direction
34#define IN_EP(endpoint) ((endpoint) & 1U ? true : false)
35#define OUT_EP(endpoint) ((endpoint) & 1U ? false : true)
36
37#define BD_OWN_MASK (1<<7)
38#define BD_DATA01_MASK (1<<6)
39#define BD_KEEP_MASK (1<<5)
40#define BD_NINC_MASK (1<<4)
41#define BD_DTS_MASK (1<<3)
42#define BD_STALL_MASK (1<<2)
43
44#define TX 1
45#define RX 0
46#define ODD 0
47#define EVEN 1
48// this macro waits a physical endpoint number
49#define EP_BDT_IDX(ep, dir, odd) (((ep * 4) + (2 * dir) + (1 * odd)))
50
51#define SETUP_TOKEN 0x0D
52#define IN_TOKEN 0x09
53#define OUT_TOKEN 0x01
54#define TOK_PID(idx) ((bdt[idx].info >> 2) & 0x0F)
55
56// for each endpt: 8 bytes
57typedef struct BDT {
58 uint8_t info; // BD[0:7]
59 uint8_t dummy; // RSVD: BD[8:15]
60 uint16_t byte_count; // BD[16:32]
61 uint32_t address; // Addr
62} BDT;
63
64
65// there are:
66// * 16 bidirectionnal endpt -> 32 physical endpt
67// * as there are ODD and EVEN buffer -> 32*2 bdt
68__attribute__((__aligned__(512))) BDT bdt[NUMBER_OF_PHYSICAL_ENDPOINTS * 2];
69uint8_t * endpoint_buffer[(NUMBER_OF_PHYSICAL_ENDPOINTS - 2) * 2];
70uint8_t * endpoint_buffer_iso[2*2];
71
72static uint8_t set_addr = 0;
73static uint8_t addr = 0;
74
75static uint32_t Data1 = 0x55555555;
76
77static uint32_t frameNumber() {
78 return((USB0->FRMNUML | (USB0->FRMNUMH << 8)) & 0x07FF);
79}
80
81uint32_t USBHAL::endpointReadcore(uint8_t endpoint, uint8_t *buffer) {
82 return 0;
83}
84
85USBHAL::USBHAL(void) {
86 // Disable IRQ
87 NVIC_DisableIRQ(USB0_IRQn);
88
89#if defined(TARGET_K64F)
90 MPU->CESR=0;
91#endif
92 // fill in callback array
93 epCallback[0] = &USBHAL::EP1_OUT_callback;
94 epCallback[1] = &USBHAL::EP1_IN_callback;
95 epCallback[2] = &USBHAL::EP2_OUT_callback;
96 epCallback[3] = &USBHAL::EP2_IN_callback;
97 epCallback[4] = &USBHAL::EP3_OUT_callback;
98 epCallback[5] = &USBHAL::EP3_IN_callback;
99 epCallback[6] = &USBHAL::EP4_OUT_callback;
100 epCallback[7] = &USBHAL::EP4_IN_callback;
101 epCallback[8] = &USBHAL::EP5_OUT_callback;
102 epCallback[9] = &USBHAL::EP5_IN_callback;
103 epCallback[10] = &USBHAL::EP6_OUT_callback;
104 epCallback[11] = &USBHAL::EP6_IN_callback;
105 epCallback[12] = &USBHAL::EP7_OUT_callback;
106 epCallback[13] = &USBHAL::EP7_IN_callback;
107 epCallback[14] = &USBHAL::EP8_OUT_callback;
108 epCallback[15] = &USBHAL::EP8_IN_callback;
109 epCallback[16] = &USBHAL::EP9_OUT_callback;
110 epCallback[17] = &USBHAL::EP9_IN_callback;
111 epCallback[18] = &USBHAL::EP10_OUT_callback;
112 epCallback[19] = &USBHAL::EP10_IN_callback;
113 epCallback[20] = &USBHAL::EP11_OUT_callback;
114 epCallback[21] = &USBHAL::EP11_IN_callback;
115 epCallback[22] = &USBHAL::EP12_OUT_callback;
116 epCallback[23] = &USBHAL::EP12_IN_callback;
117 epCallback[24] = &USBHAL::EP13_OUT_callback;
118 epCallback[25] = &USBHAL::EP13_IN_callback;
119 epCallback[26] = &USBHAL::EP14_OUT_callback;
120 epCallback[27] = &USBHAL::EP14_IN_callback;
121 epCallback[28] = &USBHAL::EP15_OUT_callback;
122 epCallback[29] = &USBHAL::EP15_IN_callback;
123
124#if defined(TARGET_KL43Z)
125 // enable USBFS clock
126 SIM->SCGC4 |= SIM_SCGC4_USBFS_MASK;
127
128 // enable the IRC48M clock
129 USB0->CLK_RECOVER_IRC_EN |= USB_CLK_RECOVER_IRC_EN_IRC_EN_MASK;
130
131 // enable the USB clock recovery tuning
132 USB0->CLK_RECOVER_CTRL |= USB_CLK_RECOVER_CTRL_CLOCK_RECOVER_EN_MASK;
133
134 // choose usb src clock
135 SIM->SOPT2 |= SIM_SOPT2_USBSRC_MASK;
136#elif defined(TARGET_INFINITY)
137 // USB clock source: FLL
138 SIM->SOPT2 |= SIM_SOPT2_USBSRC_MASK;
139
140 // enable OTG clock
141 SIM->SCGC4 |= SIM_SCGC4_USBOTG_MASK;
142#else
143 // choose usb src as PLL
144 SIM->SOPT2 &= ~SIM_SOPT2_PLLFLLSEL_MASK;
145 SIM->SOPT2 |= (SIM_SOPT2_USBSRC_MASK | (1 << SIM_SOPT2_PLLFLLSEL_SHIFT));
146
147 // enable OTG clock
148 SIM->SCGC4 |= SIM_SCGC4_USBOTG_MASK;
149#endif
150
151 // Attach IRQ
152 instance = this;
153 NVIC_SetVector(USB0_IRQn, (uint32_t)&_usbisr);
154 NVIC_EnableIRQ(USB0_IRQn);
155
156 // USB Module Configuration
157 // Reset USB Module
158 USB0->USBTRC0 |= USB_USBTRC0_USBRESET_MASK;
159 while(USB0->USBTRC0 & USB_USBTRC0_USBRESET_MASK);
160
161 // Set BDT Base Register
162 USB0->BDTPAGE1 = (uint8_t)((uint32_t)bdt>>8);
163 USB0->BDTPAGE2 = (uint8_t)((uint32_t)bdt>>16);
164 USB0->BDTPAGE3 = (uint8_t)((uint32_t)bdt>>24);
165
166 // Clear interrupt flag
167 USB0->ISTAT = 0xff;
168
169 // USB Interrupt Enablers
170 USB0->INTEN |= USB_INTEN_TOKDNEEN_MASK |
171 USB_INTEN_SOFTOKEN_MASK |
172 USB_INTEN_ERROREN_MASK |
173 USB_INTEN_USBRSTEN_MASK;
174
175 // Disable weak pull downs
176 USB0->USBCTRL &= ~(USB_USBCTRL_PDE_MASK | USB_USBCTRL_SUSP_MASK);
177
178 USB0->USBTRC0 |= 0x40;
179}
180
181USBHAL::~USBHAL(void) { }
182
183void USBHAL::connect(void) {
184 // enable USB
185 USB0->CTL |= USB_CTL_USBENSOFEN_MASK;
186 // Pull up enable
187 USB0->CONTROL |= USB_CONTROL_DPPULLUPNONOTG_MASK;
188}
189
190void USBHAL::disconnect(void) {
191 // disable USB
192 USB0->CTL &= ~USB_CTL_USBENSOFEN_MASK;
193 // Pull up disable
194 USB0->CONTROL &= ~USB_CONTROL_DPPULLUPNONOTG_MASK;
195
196 //Free buffers if required:
197 for (int i = 0; i<(NUMBER_OF_PHYSICAL_ENDPOINTS - 2) * 2; i++) {
198 free(endpoint_buffer[i]);
199 endpoint_buffer[i] = NULL;
200 }
201 free(endpoint_buffer_iso[2]);
202 endpoint_buffer_iso[2] = NULL;
203 free(endpoint_buffer_iso[0]);
204 endpoint_buffer_iso[0] = NULL;
205}
206
207void USBHAL::configureDevice(void) {
208 // not needed
209}
210
211void USBHAL::unconfigureDevice(void) {
212 // not needed
213}
214
215void USBHAL::setAddress(uint8_t address) {
216 // we don't set the address now otherwise the usb controller does not ack
217 // we set a flag instead
218 // see usbisr when an IN token is received
219 set_addr = 1;
220 addr = address;
221}
222
223bool USBHAL::realiseEndpoint(uint8_t endpoint, uint32_t maxPacket, uint32_t flags) {
224 uint32_t handshake_flag = 0;
225 uint8_t * buf;
226
227 if (endpoint > NUMBER_OF_PHYSICAL_ENDPOINTS - 1) {
228 return false;
229 }
230
231 uint32_t log_endpoint = PHY_TO_LOG(endpoint);
232
233 if ((flags & ISOCHRONOUS) == 0) {
234 handshake_flag = USB_ENDPT_EPHSHK_MASK;
235 if (IN_EP(endpoint)) {
236 if (endpoint_buffer[EP_BDT_IDX(log_endpoint, TX, ODD)] == NULL)
237 endpoint_buffer[EP_BDT_IDX(log_endpoint, TX, ODD)] = (uint8_t *) malloc (64*2);
238 buf = &endpoint_buffer[EP_BDT_IDX(log_endpoint, TX, ODD)][0];
239 } else {
240 if (endpoint_buffer[EP_BDT_IDX(log_endpoint, RX, ODD)] == NULL)
241 endpoint_buffer[EP_BDT_IDX(log_endpoint, RX, ODD)] = (uint8_t *) malloc (64*2);
242 buf = &endpoint_buffer[EP_BDT_IDX(log_endpoint, RX, ODD)][0];
243 }
244 } else {
245 if (IN_EP(endpoint)) {
246 if (endpoint_buffer_iso[2] == NULL)
247 endpoint_buffer_iso[2] = (uint8_t *) malloc (1023*2);
248 buf = &endpoint_buffer_iso[2][0];
249 } else {
250 if (endpoint_buffer_iso[0] == NULL)
251 endpoint_buffer_iso[0] = (uint8_t *) malloc (1023*2);
252 buf = &endpoint_buffer_iso[0][0];
253 }
254 }
255
256 // IN endpt -> device to host (TX)
257 if (IN_EP(endpoint)) {
258 USB0->ENDPOINT[log_endpoint].ENDPT |= handshake_flag | // ep handshaking (not if iso endpoint)
259 USB_ENDPT_EPTXEN_MASK; // en TX (IN) tran
260 bdt[EP_BDT_IDX(log_endpoint, TX, ODD )].address = (uint32_t) buf;
261 bdt[EP_BDT_IDX(log_endpoint, TX, EVEN)].address = 0;
262 }
263 // OUT endpt -> host to device (RX)
264 else {
265 USB0->ENDPOINT[log_endpoint].ENDPT |= handshake_flag | // ep handshaking (not if iso endpoint)
266 USB_ENDPT_EPRXEN_MASK; // en RX (OUT) tran.
267 bdt[EP_BDT_IDX(log_endpoint, RX, ODD )].byte_count = maxPacket;
268 bdt[EP_BDT_IDX(log_endpoint, RX, ODD )].address = (uint32_t) buf;
269 bdt[EP_BDT_IDX(log_endpoint, RX, ODD )].info = BD_OWN_MASK | BD_DTS_MASK;
270 bdt[EP_BDT_IDX(log_endpoint, RX, EVEN)].info = 0;
271 }
272
273 Data1 |= (1 << endpoint);
274
275 return true;
276}
277
278// read setup packet
279void USBHAL::EP0setup(uint8_t *buffer) {
280 uint32_t sz;
281 endpointReadResult(EP0OUT, buffer, &sz);
282}
283
284void USBHAL::EP0readStage(void) {
285 Data1 &= ~1UL; // set DATA0
286 bdt[0].info = (BD_DTS_MASK | BD_OWN_MASK);
287}
288
289void USBHAL::EP0read(void) {
290 uint32_t idx = EP_BDT_IDX(PHY_TO_LOG(EP0OUT), RX, 0);
291 bdt[idx].byte_count = MAX_PACKET_SIZE_EP0;
292}
293
294uint32_t USBHAL::EP0getReadResult(uint8_t *buffer) {
295 uint32_t sz;
296 endpointReadResult(EP0OUT, buffer, &sz);
297 return sz;
298}
299
300void USBHAL::EP0write(uint8_t *buffer, uint32_t size) {
301 endpointWrite(EP0IN, buffer, size);
302}
303
304void USBHAL::EP0getWriteResult(void) {
305}
306
307void USBHAL::EP0stall(void) {
308 stallEndpoint(EP0OUT);
309}
310
311EP_STATUS USBHAL::endpointRead(uint8_t endpoint, uint32_t maximumSize) {
312 endpoint = PHY_TO_LOG(endpoint);
313 uint32_t idx = EP_BDT_IDX(endpoint, RX, 0);
314 bdt[idx].byte_count = maximumSize;
315 return EP_PENDING;
316}
317
318EP_STATUS USBHAL::endpointReadResult(uint8_t endpoint, uint8_t * buffer, uint32_t *bytesRead) {
319 uint32_t n, sz, idx, setup = 0;
320 uint8_t not_iso;
321 uint8_t * ep_buf;
322
323 uint32_t log_endpoint = PHY_TO_LOG(endpoint);
324
325 if (endpoint > NUMBER_OF_PHYSICAL_ENDPOINTS - 1) {
326 return EP_INVALID;
327 }
328
329 // if read on a IN endpoint -> error
330 if (IN_EP(endpoint)) {
331 return EP_INVALID;
332 }
333
334 idx = EP_BDT_IDX(log_endpoint, RX, 0);
335 sz = bdt[idx].byte_count;
336 not_iso = USB0->ENDPOINT[log_endpoint].ENDPT & USB_ENDPT_EPHSHK_MASK;
337
338 //for isochronous endpoint, we don't wait an interrupt
339 if ((log_endpoint != 0) && not_iso && !(epComplete & EP(endpoint))) {
340 return EP_PENDING;
341 }
342
343 if ((log_endpoint == 0) && (TOK_PID(idx) == SETUP_TOKEN)) {
344 setup = 1;
345 }
346
347 // non iso endpoint
348 if (not_iso) {
349 ep_buf = endpoint_buffer[idx];
350 } else {
351 ep_buf = endpoint_buffer_iso[0];
352 }
353
354 for (n = 0; n < sz; n++) {
355 buffer[n] = ep_buf[n];
356 }
357
358 if (((Data1 >> endpoint) & 1) == ((bdt[idx].info >> 6) & 1)) {
359 if (setup && (buffer[6] == 0)) // if no setup data stage,
360 Data1 &= ~1UL; // set DATA0
361 else
362 Data1 ^= (1 << endpoint);
363 }
364
365 if (((Data1 >> endpoint) & 1)) {
366 bdt[idx].info = BD_DTS_MASK | BD_DATA01_MASK | BD_OWN_MASK;
367 }
368 else {
369 bdt[idx].info = BD_DTS_MASK | BD_OWN_MASK;
370 }
371
372 USB0->CTL &= ~USB_CTL_TXSUSPENDTOKENBUSY_MASK;
373 *bytesRead = sz;
374
375 epComplete &= ~EP(endpoint);
376 return EP_COMPLETED;
377}
378
379EP_STATUS USBHAL::endpointWrite(uint8_t endpoint, uint8_t *data, uint32_t size) {
380 uint32_t idx, n;
381 uint8_t * ep_buf;
382
383 if (endpoint > NUMBER_OF_PHYSICAL_ENDPOINTS - 1) {
384 return EP_INVALID;
385 }
386
387 // if write on a OUT endpoint -> error
388 if (OUT_EP(endpoint)) {
389 return EP_INVALID;
390 }
391
392 idx = EP_BDT_IDX(PHY_TO_LOG(endpoint), TX, 0);
393 bdt[idx].byte_count = size;
394
395
396 // non iso endpoint
397 if (USB0->ENDPOINT[PHY_TO_LOG(endpoint)].ENDPT & USB_ENDPT_EPHSHK_MASK) {
398 ep_buf = endpoint_buffer[idx];
399 } else {
400 ep_buf = endpoint_buffer_iso[2];
401 }
402
403 for (n = 0; n < size; n++) {
404 ep_buf[n] = data[n];
405 }
406
407 if ((Data1 >> endpoint) & 1) {
408 bdt[idx].info = BD_OWN_MASK | BD_DTS_MASK;
409 } else {
410 bdt[idx].info = BD_OWN_MASK | BD_DTS_MASK | BD_DATA01_MASK;
411 }
412
413 Data1 ^= (1 << endpoint);
414
415 return EP_PENDING;
416}
417
418EP_STATUS USBHAL::endpointWriteResult(uint8_t endpoint) {
419 if (epComplete & EP(endpoint)) {
420 epComplete &= ~EP(endpoint);
421 return EP_COMPLETED;
422 }
423
424 return EP_PENDING;
425}
426
427void USBHAL::stallEndpoint(uint8_t endpoint) {
428 USB0->ENDPOINT[PHY_TO_LOG(endpoint)].ENDPT |= USB_ENDPT_EPSTALL_MASK;
429}
430
431void USBHAL::unstallEndpoint(uint8_t endpoint) {
432 USB0->ENDPOINT[PHY_TO_LOG(endpoint)].ENDPT &= ~USB_ENDPT_EPSTALL_MASK;
433}
434
435bool USBHAL::getEndpointStallState(uint8_t endpoint) {
436 uint8_t stall = (USB0->ENDPOINT[PHY_TO_LOG(endpoint)].ENDPT & USB_ENDPT_EPSTALL_MASK);
437 return (stall) ? true : false;
438}
439
440void USBHAL::remoteWakeup(void) {
441 // [TODO]
442}
443
444
445void USBHAL::_usbisr(void) {
446 instance->usbisr();
447}
448
449
450void USBHAL::usbisr(void) {
451 uint8_t i;
452 uint8_t istat = USB0->ISTAT;
453
454 // reset interrupt
455 if (istat & USB_ISTAT_USBRST_MASK) {
456 // disable all endpt
457 for(i = 0; i < 16; i++) {
458 USB0->ENDPOINT[i].ENDPT = 0x00;
459 }
460
461 // enable control endpoint
462 realiseEndpoint(EP0OUT, MAX_PACKET_SIZE_EP0, 0);
463 realiseEndpoint(EP0IN, MAX_PACKET_SIZE_EP0, 0);
464
465 Data1 = 0x55555555;
466 USB0->CTL |= USB_CTL_ODDRST_MASK;
467
468 USB0->ISTAT = 0xFF; // clear all interrupt status flags
469 USB0->ERRSTAT = 0xFF; // clear all error flags
470 USB0->ERREN = 0xFF; // enable error interrupt sources
471 USB0->ADDR = 0x00; // set default address
472
473 return;
474 }
475
476 // resume interrupt
477 if (istat & USB_ISTAT_RESUME_MASK) {
478 USB0->ISTAT = USB_ISTAT_RESUME_MASK;
479 }
480
481 // SOF interrupt
482 if (istat & USB_ISTAT_SOFTOK_MASK) {
483 USB0->ISTAT = USB_ISTAT_SOFTOK_MASK;
484 // SOF event, read frame number
485 SOF(frameNumber());
486 }
487
488 // stall interrupt
489 if (istat & 1<<7) {
490 if (USB0->ENDPOINT[0].ENDPT & USB_ENDPT_EPSTALL_MASK)
491 USB0->ENDPOINT[0].ENDPT &= ~USB_ENDPT_EPSTALL_MASK;
492 USB0->ISTAT |= USB_ISTAT_STALL_MASK;
493 }
494
495 // token interrupt
496 if (istat & 1<<3) {
497 uint32_t num = (USB0->STAT >> 4) & 0x0F;
498 uint32_t dir = (USB0->STAT >> 3) & 0x01;
499 uint32_t ev_odd = (USB0->STAT >> 2) & 0x01;
500
501 // setup packet
502 if ((num == 0) && (TOK_PID((EP_BDT_IDX(num, dir, ev_odd))) == SETUP_TOKEN)) {
503 Data1 &= ~0x02;
504 bdt[EP_BDT_IDX(0, TX, EVEN)].info &= ~BD_OWN_MASK;
505 bdt[EP_BDT_IDX(0, TX, ODD)].info &= ~BD_OWN_MASK;
506
507 // EP0 SETUP event (SETUP data received)
508 EP0setupCallback();
509
510 } else {
511 // OUT packet
512 if (TOK_PID((EP_BDT_IDX(num, dir, ev_odd))) == OUT_TOKEN) {
513 if (num == 0)
514 EP0out();
515 else {
516 epComplete |= (1 << EP(num));
517 if ((instance->*(epCallback[EP(num) - 2]))()) {
518 epComplete &= ~(1 << EP(num));
519 }
520 }
521 }
522
523 // IN packet
524 if (TOK_PID((EP_BDT_IDX(num, dir, ev_odd))) == IN_TOKEN) {
525 if (num == 0) {
526 EP0in();
527 if (set_addr == 1) {
528 USB0->ADDR = addr & 0x7F;
529 set_addr = 0;
530 }
531 }
532 else {
533 epComplete |= (1 << (EP(num) + 1));
534 if ((instance->*(epCallback[EP(num) + 1 - 2]))()) {
535 epComplete &= ~(1 << (EP(num) + 1));
536 }
537 }
538 }
539 }
540
541 USB0->ISTAT = USB_ISTAT_TOKDNE_MASK;
542 }
543
544 // sleep interrupt
545 if (istat & 1<<4) {
546 USB0->ISTAT |= USB_ISTAT_SLEEP_MASK;
547 }
548
549 // error interrupt
550 if (istat & USB_ISTAT_ERROR_MASK) {
551 USB0->ERRSTAT = 0xFF;
552 USB0->ISTAT |= USB_ISTAT_ERROR_MASK;
553 }
554}
555
556
557#endif
diff --git a/keyboard/infinity/tool/README b/keyboard/infinity/tool/README
new file mode 100644
index 000000000..3dd331656
--- /dev/null
+++ b/keyboard/infinity/tool/README
@@ -0,0 +1,25 @@
1OpenOCD config files for Kinetis
2================================
3http://nemuisan.blog.bai.ne.jp/?eid=192848#OPENOCD
4
5These are needed for SWD debug and programing bootloader. To flash keyboard firmware use 'dfu-util'.
6
7Flash security of Freescale kinetis
8-----------------------------------
9If FSEC of flash config is changed accidentally SWD/JTAG you can't get debug access until doing 'mdm mass_erase' with JTAG, CMSIS-DAP or OpenSAD adapter. HLA(high level adapter) like stlink doesn't work for this.
10
11
12Example
13-------
14Debug:
15 $ openocd -s tool -f tool/openocd.cfg
16 $ arm-none-eabi-gdb build/infinity.elf -ex "target remote localhost:3333"
17
18Flash bootloader:
19 $ openocd -s tool -f tool/openocd.cfg -c "mt_flash kiibohd_bootloader.bin"
20
21
22Infinity SWD pinout
23-------------------
24SWD pins are placed next to reset button; SWD_CLK, SWD_DIO, GND, VCC from top.
25Note that RESET is also needed to get full control with OpenOCD.
diff --git a/tool/mbed/lpc11u35_501.mk b/tool/mbed/lpc11u35_501.mk
index 15e14910c..328d03d66 100644
--- a/tool/mbed/lpc11u35_501.mk
+++ b/tool/mbed/lpc11u35_501.mk
@@ -17,6 +17,7 @@ CC_SYMBOLS = \
17 -D__MBED__=1 17 -D__MBED__=1
18 18
19OBJECTS += \ 19OBJECTS += \
20 $(OBJDIR)/libraries/USBDevice/USBDevice/USBHAL_LPC11U.o \
20 $(OBJDIR)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX/TOOLCHAIN_GCC_ARM/startup_LPC11xx.o \ 21 $(OBJDIR)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX/TOOLCHAIN_GCC_ARM/startup_LPC11xx.o \
21 $(OBJDIR)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX/cmsis_nvic.o \ 22 $(OBJDIR)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX/cmsis_nvic.o \
22 $(OBJDIR)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX/system_LPC11Uxx.o \ 23 $(OBJDIR)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX/system_LPC11Uxx.o \
diff --git a/tool/mbed/mbed.mk b/tool/mbed/mbed.mk
index db322b260..2657a0fd3 100644
--- a/tool/mbed/mbed.mk
+++ b/tool/mbed/mbed.mk
@@ -4,7 +4,9 @@
4OBJECTS += \ 4OBJECTS += \
5 $(OBJDIR)/libraries/mbed/common/gpio.o \ 5 $(OBJDIR)/libraries/mbed/common/gpio.o \
6 $(OBJDIR)/libraries/mbed/common/us_ticker_api.o \ 6 $(OBJDIR)/libraries/mbed/common/us_ticker_api.o \
7 $(OBJDIR)/libraries/mbed/common/wait_api.o 7 $(OBJDIR)/libraries/mbed/common/wait_api.o \
8 $(OBJDIR)/libraries/USBDevice/USBDevice/USBDevice.o
9
8 10
9# $(OBJDIR)/libraries/mbed/common/assert.o \ 11# $(OBJDIR)/libraries/mbed/common/assert.o \
10# $(OBJDIR)/libraries/mbed/common/board.o \ 12# $(OBJDIR)/libraries/mbed/common/board.o \
@@ -75,9 +77,9 @@ INCLUDE_PATHS += \
75 -I$(MBED_DIR)/libraries/USBDevice/USBSerial 77 -I$(MBED_DIR)/libraries/USBDevice/USBSerial
76 78
77# TMK mbed protocol 79# TMK mbed protocol
78#OBJECTS += \ 80OBJECTS += \
79# $(OBJDIR)/protocol/mbed/mbed_driver.o \ 81 $(OBJDIR)/protocol/mbed/mbed_driver.o \
80# $(OBJDIR)/protocol/mbed/HIDKeyboard.o 82 $(OBJDIR)/protocol/mbed/HIDKeyboard.o
81 83
82INCLUDE_PATHS += \ 84INCLUDE_PATHS += \
83 -I$(TMK_DIR)/protocol/mbed 85 -I$(TMK_DIR)/protocol/mbed