changeset 424:0d1cc6ec4af7

Merge branch 'master' of github.com:kiibohd/controller
author CryHam <cryham@gmail.com>
date Tue, 01 Mar 2016 19:40:00 +0100
parents be6b57c5b438 (diff) 23a1868b4ac2 (current diff)
children 971e88d4420a
files Scan/MatrixARM/matrix_scan.c
diffstat 3 files changed, 178 insertions(+), 97 deletions(-) [+]
line wrap: on
line diff
--- a/Scan/CK3/defaultMap.kll	Sun Feb 21 19:56:52 2016 -0800
+++ b/Scan/CK3/defaultMap.kll	Tue Mar 01 19:40:00 2016 +0100
@@ -1,85 +1,132 @@
 Name = CK3;
 Version = 0.3;
 Author = "Crystal Hammer 2016";
-KLL = 0.3c;
+KLL = 0.3d;
 
 # Modified Date
-Date = 2016-02-19;
+Date = 2016-03-01;
+
+# this is nearly the default map
+
+S0x0F : U"Esc";
+S0x8C : U"F1";
+S0x8B : U"F2";
+S0x67 : U"F3";
+S0x0D : U"F4";
+S0x6E : U"F5";
+S0x06 : U"F6";
+S0x5F : U"F7";
+S0x83 : U"F8";
+S0x7F : U"F9";
+S0x6D : U"F10";
+S0x01 : U"F11";
+S0x13 : U"F12";
+S0x6F : U"PrintScreen";
+S0x4B : U"ScrollLock";
+S0x4A : U"Pause";
+S0x39 : U"F16";
+
+S0x8D : U"BackTick";
+S0x7B : U"1";
+S0x7A : U"2";
+S0x79 : U"3";
+S0x74 : U"4";
+S0x86 : U"5";
+S0x85 : U"6";
+S0x73 : U"7";
+S0x72 : U"8";
+S0x71 : U"9";
+S0x6C : U"0";
+S0x7E : U"-";
+S0x84 : U"=";
+S0x5B : U"Backspace";
 
 
-S0x00 : U"Esc";
-S0x01 : U"1";
-S0x02 : U"2";
-S0x03 : U"3";
-S0x04 : U"4";
-S0x05 : U"5";
-S0x06 : U"6";
-S0x07 : U"7";
-S0x08 : U"8";
-S0x09 : U"9";
-S0x0A : U"0";
-S0x0B : U"Minus";
-S0x0C : U"Equal";
-S0x0D : U"Backslash";
-S0x0E : U"Backtick";
-S0x0F : U"Tab";
-S0x10 : U"Q";
-S0x11 : U"W";
-S0x12 : U"E";
-S0x13 : U"R";
-S0x14 : U"T";
-S0x15 : U"Y";
-S0x16 : U"U";
-S0x17 : U"I";
-S0x18 : U"O";
-S0x19 : U"P";
-S0x1A : U"LBrace";
-S0x1B : U"RBrace";
-S0x1C : U"Backspace";
-S0x1D : U"Ctrl";
-S0x1E : U"A";
-S0x1F : U"S";
-S0x20 : U"D";
-S0x21 : U"F";
-S0x22 : U"G";
-S0x23 : U"H";
-S0x24 : U"J";
-S0x25 : U"K";
-S0x26 : U"L";
-S0x27 : U"Semicolon";
-S0x28 : U"Quote";
-S0x29 : U"Enter";
-S0x2A : U"LShift";
-S0x2B : U"Z";
-S0x2C : U"X";
-S0x2D : U"C";
-S0x2E : U"V";
-S0x2F : U"B";
-S0x30 : U"N";
-S0x31 : U"M";
-S0x32 : U"Comma";
-S0x33 : U"Period";
-S0x34 : U"Slash";
-S0x35 : U"RShift";
-S0x36 : U"Function1"; # Fun key
-S0x37 : U"Function2"; # Left Blank Key
-S0x38 : U"LAlt";
-S0x39 : U"LGui";
-S0x3A : U"Space";
-S0x3B : U"RGui";
-S0x3C : U"RAlt";
-S0x3D : U"Function3"; # Right Blank Key 1
-S0x3E : U"Function4"; # Right Blank Key 2
+S0x69 : U"Tab";
+S0x57 : U"Q";
+S0x56 : U"W";
+S0x55 : U"E";
+S0x50 : U"R";
+S0x62 : U"T";
+S0x61 : U"Y";
+S0x4F : U"U";
+S0x4E : U"I";
+S0x4D : U"O";
+S0x48 : U"P";
+S0x5A : U"[";
+S0x60 : U"]";
+S0x37 : U"\";
+
+S0x68 : U"CapsLock";
+S0x45 : U"A";
+S0x44 : U"S";
+S0x43 : U"D";
+S0x3E : U"F";
+S0x08 : U"G";
+S0x07 : U"H";
+S0x3D : U"J";
+S0x3C : U"K";
+S0x3B : U"L";
+S0x36 : U";";
+S0x00 : U"'";
+S0x25 : U"Enter";
+
+S0x5E : U"LShift";
+S0x33 : U"Z";
+S0x32 : U"X";
+S0x31 : U"C";
+S0x2C : U"V";
+S0x1A : U"B";
+S0x19 : U"N";
+S0x2B : U"M";
+S0x2A : U",";
+S0x29 : U".";
+S0x12 : U"/";
+S0x3A : U"RShift";
 
-
-# Custom Action Examples
+# bottom
+S0x80 : U"LCtrl";
+S0x6A : U"LGui";
+S0x0E : U"LAlt";
+S0x03 : U"LAlt";
+S0x09 : U"Space";
+S0x15 : U"RAlt";
+S0x17 : U"RGui";
+S0x88 : U"RCtrl";
+S0x87 : U"RCtrl";
 
-# Example capability, prints to cli
-action1 => CustomAction_action1_capability(); # No arguments
+# middle right column, custom
+S0x8A : U"Esc";
+S0x89 : U"Backspace";
+S0x77 : U"Enter";
+S0x78 : U"RShift";
 
-# Blocks given USB Code, must be used with blockLink
-# Simple example, supports only blocking a single key at a time
-# Keys must be specified using numbers see Macro/PartialMap/usb_hid.h
-blockHold => CustomAction_blockHold_capability( usbCode : 1 ); # Single 8-bit argument
-blockKey => CustomAction_blockKey_capability( usbCode : 1 );
+# arrows
+S0x1E : U"Left";
+S0x0C : U"Up";
+S0x1B : U"Down";
+S0x1C : U"Right";
+# S0x1C : U"RCtrl";
+
+# numpad
+S0x2D : U"NumLock";
+S0x2E : U"P/";
+S0x2F : U"P*";
+S0x1D : U"P-";
 
+S0x51 : U"P7";
+S0x52 : U"P8";
+S0x53 : U"P9";
+S0x54 : U"P+";
+
+S0x63 : U"P4";
+S0x64 : U"P5";
+S0x65 : U"P6";
+
+S0x3F : U"P1";
+S0x40 : U"P2";
+S0x41 : U"P3";
+S0x42 : U"PEnter";
+
+S0x0A : U"P0";
+S0x0B : U"P.";
--- a/Scan/CK3/matrix.h	Sun Feb 21 19:56:52 2016 -0800
+++ b/Scan/CK3/matrix.h	Tue Mar 01 19:40:00 2016 +0100
@@ -1,4 +1,4 @@
-/* Copyright (C) 2014-2015 by Jacob Alexander
+/* Copyright (C) 2014-2016 by Jacob Alexander, Crystal Hammer
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -27,28 +27,42 @@
 #include <matrix_setup.h>
 
 
-
 // ----- Matrix Definition -----
+//  CK3
+//  Columns (Strobe)  18
+//  Rows    (Sense)   8
 
-// Freescale ARM MK20's support GPIO PTA, PTB, PTC, PTD and PTE 0..31
-// Not all chips have access to all of these pins (most don't have 160 pins :P)
-//
-// NOTE:
-// Before using a pin, make sure it supports being a GPIO *and* doesn't have a default pull-up/pull-down
-// Checking this is completely on the ownness of the user
+//   This is the default map of just A4Tech KX-100 matrix
+//   scan codes for keys are defined in defaultMap.kll
+/*
+      1|   2    3    4    5    6    7    8    9    10  11  12   13   14   15   16   17   18  
+   -
+   1  Mcmp Bstp Esc  \    F4   Up   Del  Ins  Spc  G   H   F6   ==   Vol- AltL xx   F11  '   
+   2  Calc ExA4 ExC2 ExE2 ExE1 <-   Sub  ->   Dn   B   N   ExC1 Apps Mnxt AltR xx   F12  /   
+   3  Mstp Bbck Z    X    C    Mpau Mul  Div  NumL V   M   ,    .    Vol+ xx   CtrR Ent  \   
+   4  GuiR Bfwd A    S    D    Ent  PgDn Dn   End  F   J   K    L    ShiR xx   ==   \    ;   
+   5  xx   Mail Q    W    E    Add  PgUp Up   Home R   U   I    O    xx   ScrL Paus ExE3 P   
+   6  ExB1 GuiL Tab  Caps F3   RB~  ->   Del  <-   T   Y   ]    F7   ShiL ==   Pwr  Back [   
+   7  xx   Bsch 1    2    3    End  PgDn xx   Pwr  4   7   8    9    Msel Ptr  F5   F10  0   
+   8  Bhom Vmut `~   F1   F2   Home PgUp Ins  Del  5   6   =    F8   Mprv ==   CtrL F9   -   
 
-//
-// Columns (Strobe)  //  PTB0..3,16,17 PTC4,5 PTD0
-// Rows	   (Sense)   //  PTD1..7
-
-// Define Rows (Sense) and Columns (Strobes)
-GPIO_Pin Matrix_cols[] = { gpio(B,0), gpio(B,1), gpio(B,2), gpio(B,3), gpio(B,16), gpio(B,17), gpio(C,4), gpio(C,6), gpio(D,0) };
-GPIO_Pin Matrix_rows[] = { gpio(D,1), gpio(D,2), gpio(D,3), gpio(D,4), gpio(D,5), gpio(D,6), gpio(D,7) };
+     rows -       columns |
+   1 3 5 7    1 3 5 7 9 11 13 15 17
+    2 4 6 8    2 4 6 8 10 12 14 16 18   connectors, PCB view
+*/
+GPIO_Pin Matrix_cols[] = {
+	gpio(B,16), gpio(B,17), gpio(D,0), gpio(A,12), gpio(A,13), gpio(D,7), gpio(D,4), gpio(D,2), gpio(D,3),
+	gpio(C,2), gpio(C,1), gpio(D,6), gpio(D,5), gpio(B,2), gpio(B,3), gpio(B,1), gpio(B,0), gpio(C,0)  };
+GPIO_Pin Matrix_rows[] = {
+	gpio(C,10), gpio(C,11), gpio(B,18), gpio(A,4), gpio(A,5), gpio(B,19), gpio(C,9), gpio(C,8) };
 
 // Define type of scan matrix
-Config Matrix_type = Config_Pulldown;
+Config Matrix_type = Config_Pullup;
 
 
 // Define this if your matrix has ghosting (i.e. regular keyboard without diodes)
 // this will enable the anti-ghosting code
 #define GHOSTING_MATRIX
+
+// delay in microseconds before and after each strobe change during matrix scan
+#define STROBE_DELAY  10
--- a/Scan/MatrixARM/matrix_scan.c	Sun Feb 21 19:56:52 2016 -0800
+++ b/Scan/MatrixARM/matrix_scan.c	Tue Mar 01 19:40:00 2016 +0100
@@ -30,6 +30,7 @@
 #include <led.h>
 #include <print.h>
 #include <macro.h>
+#include <Lib/delay.h>
 
 // Local Includes
 #include "matrix_scan.h"
@@ -110,7 +111,9 @@
 	// Assumes 0x40 between GPIO Port registers and 0x1000 between PORT pin registers
 	// See Lib/mk20dx.h
 	volatile unsigned int *GPIO_PDDR = (unsigned int*)(&GPIOA_PDDR) + gpio_offset;
+	#ifndef GHOSTING_MATRIX
 	volatile unsigned int *GPIO_PSOR = (unsigned int*)(&GPIOA_PSOR) + gpio_offset;
+	#endif
 	volatile unsigned int *GPIO_PCOR = (unsigned int*)(&GPIOA_PCOR) + gpio_offset;
 	volatile unsigned int *GPIO_PDIR = (unsigned int*)(&GPIOA_PDIR) + gpio_offset;
 	volatile unsigned int *PORT_PCR  = (unsigned int*)(&PORTA_PCR0) + port_offset;
@@ -119,23 +122,30 @@
 	switch ( type )
 	{
 	case Type_StrobeOn:
+		#ifdef GHOSTING_MATRIX
+		*GPIO_PCOR |= (1 << gpio.pin);
+		*GPIO_PDDR |= (1 << gpio.pin);  // output, low
+		#else
 		*GPIO_PSOR |= (1 << gpio.pin);
-		#ifdef GHOSTING_MATRIX
-		*GPIO_PDDR |= (1 << gpio.pin);  // output
 		#endif
 		break;
 
 	case Type_StrobeOff:
-		*GPIO_PCOR |= (1 << gpio.pin);
 		#ifdef GHOSTING_MATRIX
 		// Ghosting martix needs to put not used (off) strobes in high impedance state
 		*GPIO_PDDR &= ~(1 << gpio.pin);  // input, high Z state
 		#endif
+		*GPIO_PCOR |= (1 << gpio.pin);
 		break;
 
 	case Type_StrobeSetup:
+		#ifdef GHOSTING_MATRIX
+		*GPIO_PDDR &= ~(1 << gpio.pin);  // input, high Z state
+		*GPIO_PCOR |= (1 << gpio.pin);
+		#else
 		// Set as output pin
 		*GPIO_PDDR |= (1 << gpio.pin);
+		#endif
 
 		// Configure pin with slow slew, high drive strength and GPIO mux
 		*PORT_PCR = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
@@ -154,7 +164,11 @@
 		break;
 
 	case Type_Sense:
+		#ifdef GHOSTING_MATRIX  // inverted
+		return *GPIO_PDIR & (1 << gpio.pin) ? 0 : 1;
+		#else
 		return *GPIO_PDIR & (1 << gpio.pin) ? 1 : 0;
+		#endif
 
 	case Type_SenseSetup:
 		// Set as input pin
@@ -294,9 +308,19 @@
 	// For each strobe, scan each of the sense pins
 	for ( uint8_t strobe = 0; strobe < Matrix_colsNum; strobe++ )
 	{
+		#ifdef STROBE_DELAY
+		uint32_t start = micros();
+		while ((micros() - start) < STROBE_DELAY);
+		#endif
+
 		// Strobe Pin
 		Matrix_pin( Matrix_cols[ strobe ], Type_StrobeOn );
 
+		#ifdef STROBE_DELAY
+		start = micros();
+		while ((micros() - start) < STROBE_DELAY);
+		#endif
+
 		// Scan each of the sense pins
 		for ( uint8_t sense = 0; sense < Matrix_rowsNum; sense++ )
 		{
@@ -510,10 +534,6 @@
 			KeyPosition k = !st->cur
 				? (!st->prev ? KeyState_Off : KeyState_Release)
 				: ( st->prev ? KeyState_Hold : KeyState_Press);
-			//if (!st->cur && !st->prev)  k = KeyState_Off; else
-			//if ( st->cur &&  st->prev)  k = KeyState_Hold; else
-			//if ( st->cur && !st->prev)  k = KeyState_Press; else
-			//if (!st->cur &&  st->prev)  k = KeyState_Release;
 			Macro_keyState( key, k );
 		}
 	}