From 0e6f107ea108bea0b179bcc2a2ac17d3ba49e1a7 Mon Sep 17 00:00:00 2001 From: Dan McGregor Date: Mon, 10 Aug 2015 14:49:46 -0600 Subject: [PATCH 01/23] Start removing select Linux-isms bash might not be in /bin. Don't expect it there. --- Bootloader/Scripts/easyMode.bash | 2 +- Bootloader/Scripts/generateManufacturingImage.bash | 2 +- Bootloader/Scripts/ledTest.bash | 2 +- Bootloader/Scripts/swdLoad.bash | 2 +- Keyboards/cmake.bash | 2 +- Keyboards/ergodox.bash | 2 +- Keyboards/infinity.bash | 2 +- Keyboards/template.bash | 2 +- Keyboards/whitefox.bash | 2 +- Lib/CMake/sizeCalculator | 2 +- Lib/CMake/writer | 2 +- LoadFile/load.dfu | 2 +- LoadFile/load.teensy | 2 +- LoadFile/winload.teensy | 2 +- Scan/ISSILed/exampleAPI.bash | 2 +- Scan/STLcd/exampleAPI.bash | 2 +- buildall.bash | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Bootloader/Scripts/easyMode.bash b/Bootloader/Scripts/easyMode.bash index 65b4848..ece0b53 100644 --- a/Bootloader/Scripts/easyMode.bash +++ b/Bootloader/Scripts/easyMode.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Just in case there was an extra ledTest.bash (don't care if error) rm /dev/ttyACM0 diff --git a/Bootloader/Scripts/generateManufacturingImage.bash b/Bootloader/Scripts/generateManufacturingImage.bash index ef46e2d..455e570 100755 --- a/Bootloader/Scripts/generateManufacturingImage.bash +++ b/Bootloader/Scripts/generateManufacturingImage.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Combines a given bootloader image and firmware image into a single firmware binary # Manufacturing deliverable diff --git a/Bootloader/Scripts/ledTest.bash b/Bootloader/Scripts/ledTest.bash index 07aa9d8..9c8565f 100644 --- a/Bootloader/Scripts/ledTest.bash +++ b/Bootloader/Scripts/ledTest.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash printf "led\r" > /dev/ttyACM0 diff --git a/Bootloader/Scripts/swdLoad.bash b/Bootloader/Scripts/swdLoad.bash index 12b1e9b..6c333bf 100755 --- a/Bootloader/Scripts/swdLoad.bash +++ b/Bootloader/Scripts/swdLoad.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Loads firmware image using an SWD Flasher # Uses MCHCK ruby flasher toolchain # NOTE: Only tested with a buspirate on Linux diff --git a/Keyboards/cmake.bash b/Keyboards/cmake.bash index 3a1b6e4..9587abe 100644 --- a/Keyboards/cmake.bash +++ b/Keyboards/cmake.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # This is bash lib file for the convenience build scripts # Don't call this script directly # Jacob Alexander 2015 diff --git a/Keyboards/ergodox.bash b/Keyboards/ergodox.bash index b07eb16..85f85a2 100755 --- a/Keyboards/ergodox.bash +++ b/Keyboards/ergodox.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # This is a build script template # These build scripts are just a convenience for configuring your keyboard (less daunting than CMake) # Jacob Alexander 2015 diff --git a/Keyboards/infinity.bash b/Keyboards/infinity.bash index bc3c0ac..b790dd5 100755 --- a/Keyboards/infinity.bash +++ b/Keyboards/infinity.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # This is a build script template # These build scripts are just a convenience for configuring your keyboard (less daunting than CMake) # Jacob Alexander 2015 diff --git a/Keyboards/template.bash b/Keyboards/template.bash index b1e876f..c522726 100755 --- a/Keyboards/template.bash +++ b/Keyboards/template.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # This is a build script template # These build scripts are just a convenience for configuring your keyboard (less daunting than CMake) # Jacob Alexander 2015 diff --git a/Keyboards/whitefox.bash b/Keyboards/whitefox.bash index c5ff835..049986a 100755 --- a/Keyboards/whitefox.bash +++ b/Keyboards/whitefox.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # This is a build script template # These build scripts are just a convenience for configuring your keyboard (less daunting than CMake) # Jacob Alexander 2015 diff --git a/Lib/CMake/sizeCalculator b/Lib/CMake/sizeCalculator index affb163..b0ab2e6 100755 --- a/Lib/CMake/sizeCalculator +++ b/Lib/CMake/sizeCalculator @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash #| Jacob Alexander 2014 #| Arg List #| 1 - size binary (e.g. avr-size) diff --git a/Lib/CMake/writer b/Lib/CMake/writer index 23f94dd..a5eb27b 100755 --- a/Lib/CMake/writer +++ b/Lib/CMake/writer @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash #| Jacob Alexander 2014 #| Arg List #| 1 - File to write to (e.g. final_chip) diff --git a/LoadFile/load.dfu b/LoadFile/load.dfu index d99c5e6..5c7719c 100755 --- a/LoadFile/load.dfu +++ b/LoadFile/load.dfu @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Convenience script for loading firmware onto a dfu type device # By default, initiates dfu-util diff --git a/LoadFile/load.teensy b/LoadFile/load.teensy index 751a97f..b86dd11 100755 --- a/LoadFile/load.teensy +++ b/LoadFile/load.teensy @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Convenience script for loading firmware onto a teensy type device # By default, initiates teensy-load-cli diff --git a/LoadFile/winload.teensy b/LoadFile/winload.teensy index 1d86daf..4928197 100755 --- a/LoadFile/winload.teensy +++ b/LoadFile/winload.teensy @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Convenience script for loading firmware onto a teensy type device # By default, initiates teensy-load-cli diff --git a/Scan/ISSILed/exampleAPI.bash b/Scan/ISSILed/exampleAPI.bash index 5d66c37..be869fa 100755 --- a/Scan/ISSILed/exampleAPI.bash +++ b/Scan/ISSILed/exampleAPI.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # ISSILed # Virtual Serial Port API Example # Jacob Alexander 2015 diff --git a/Scan/STLcd/exampleAPI.bash b/Scan/STLcd/exampleAPI.bash index 8c2dda5..c2a611e 100755 --- a/Scan/STLcd/exampleAPI.bash +++ b/Scan/STLcd/exampleAPI.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # STLcd # Virtual Serial Port API Example # Jacob Alexander 2015 diff --git a/buildall.bash b/buildall.bash index dd3a7cc..4f5aaa9 100755 --- a/buildall.bash +++ b/buildall.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ###| Builder Script |### # # Builds all permutations of modules From 862e7ea39d05660b740941c9ea72b1bc4e7ccaff Mon Sep 17 00:00:00 2001 From: Kevin Frei Date: Sat, 2 Jan 2016 17:43:05 -0800 Subject: [PATCH 02/23] Fix a handful of infinite loops that occur if you have more than 254 macros --- Macro/PartialMap/macro.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Macro/PartialMap/macro.c b/Macro/PartialMap/macro.c index e861f0e..dc51751 100644 --- a/Macro/PartialMap/macro.c +++ b/Macro/PartialMap/macro.c @@ -135,7 +135,7 @@ uint16_t macroStepCounter = 0; // Key Trigger List Buffer and Layer Cache // The layer cache is set on press only, hold and release events refer to the value set on press TriggerGuide macroTriggerListBuffer[ MaxScanCode ]; -uint8_t macroTriggerListBufferSize = 0; +var_uint_t macroTriggerListBufferSize = 0; var_uint_t macroTriggerListLayerCache[ MaxScanCode ]; // Pending Trigger Macro Index List @@ -557,7 +557,7 @@ inline void Macro_interconnectAdd( void *trigger_ptr ) // Add trigger to the Interconnect Cache // During each processing loop, a scancode may be re-added depending on it's state - for ( uint8_t c = 0; c < macroInterconnectCacheSize; c++ ) + for ( var_uint_t c = 0; c < macroInterconnectCacheSize; c++ ) { // Check if the same ScanCode if ( macroInterconnectCache[ c ].scanCode == trigger->scanCode ) @@ -699,7 +699,7 @@ inline void Macro_appendResultMacroToPendingList( const TriggerMacro *triggerMac uint8_t scanCode = ((TriggerGuide*)&triggerMacro->guide[ pos - TriggerGuideSize ])->scanCode; // Lookup scanCode in buffer list for the current state and stateType - for ( uint8_t keyIndex = 0; keyIndex < macroTriggerListBufferSize; keyIndex++ ) + for ( var_uint_t keyIndex = 0; keyIndex < macroTriggerListBufferSize; keyIndex++ ) { if ( macroTriggerListBuffer[ keyIndex ].scanCode == scanCode ) { @@ -905,7 +905,7 @@ TriggerMacroEval Macro_evalTriggerMacro( var_uint_t triggerMacroIndex ) TriggerMacroVote vote = TriggerMacroVote_Invalid; // Iterate through the key buffer, comparing to each key in the combo - for ( uint8_t key = 0; key < macroTriggerListBufferSize; key++ ) + for ( var_uint_t key = 0; key < macroTriggerListBufferSize; key++ ) { // Lookup key information TriggerGuide *keyInfo = ¯oTriggerListBuffer[ key ]; @@ -1065,7 +1065,7 @@ inline ResultMacroEval Macro_evalResultMacro( var_uint_t resultMacroIndex ) inline void Macro_updateTriggerMacroPendingList() { // Iterate over the macroTriggerListBuffer to add any new Trigger Macros to the pending list - for ( uint8_t key = 0; key < macroTriggerListBufferSize; key++ ) + for ( var_uint_t key = 0; key < macroTriggerListBufferSize; key++ ) { // TODO LED States // TODO Analog Switches @@ -1586,7 +1586,7 @@ void cliFunc_macroList( char* args ) info_msg("Pending Key Events: "); printInt16( (uint16_t)macroTriggerListBufferSize ); print(" : "); - for ( uint8_t key = 0; key < macroTriggerListBufferSize; key++ ) + for ( var_uint_t key = 0; key < macroTriggerListBufferSize; key++ ) { printHex( macroTriggerListBuffer[ key ].scanCode ); print(" "); From e6437d603fc62e312d8615801e48f66a36a1b367 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Wed, 13 Jan 2016 15:03:29 -0800 Subject: [PATCH 03/23] Adding comment for the Teensy 3.2 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f14bbd..dcb0c94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ set( CHIP # "at90usb1286" # Teensy++ 2.0 (avr) # "mk20dx128" # Teensy 3.0 (arm) "mk20dx128vlf5" # McHCK mk20dx128vlf5 -# "mk20dx256" # Teensy 3.1 (arm) +# "mk20dx256" # Teensy 3.1,3.2 (arm) # "mk20dx256vlh7" # Kiibohd-dfu mk20dx256vlh7 CACHE STRING "Microcontroller Chip" ) From 52c8ffc964c20b20c6b8e6a3b28eac62c5d5326b Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Wed, 13 Jan 2016 15:04:45 -0800 Subject: [PATCH 04/23] Updating README for Teensy 3.2 support --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 7039d59..9e0d5c4 100644 --- a/README.markdown +++ b/README.markdown @@ -39,7 +39,7 @@ Supported Microcontrollers * Teensy 2.0 (Partial) * Teensy 2.0++ * Teensy 3.0 -* Teensy 3.1 +* Teensy 3.1/3.2 * mk20dx128vlf5 * mk20dx256vlh7 From 8c858e4483b61b0622e3663647a881d0a3150473 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Wed, 27 Jan 2016 20:41:15 -0800 Subject: [PATCH 05/23] Setting WhiteFox LEDs as defaulting to on --- Scan/WhiteFox/defaultMap.kll | 44 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Scan/WhiteFox/defaultMap.kll b/Scan/WhiteFox/defaultMap.kll index 798a0c7..6a4e641 100644 --- a/Scan/WhiteFox/defaultMap.kll +++ b/Scan/WhiteFox/defaultMap.kll @@ -102,28 +102,28 @@ ISSILedMask1 = " # # Each LED channel supports 256 levels (8-bit control) # By default, LEDs are set to 0 brightness -ISSILedBrightness1 = " -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C1-1 -> C1-16 */ -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C2-1 -> C2-16 */ -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C3-1 -> C3-16 */ -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C4-1 -> C4-16 */ -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C5-1 -> C5-16 */ -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C6-1 -> C6-16 */ -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C7-1 -> C7-16 */ -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C8-1 -> C8-16 */ -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C9-1 -> C9-16 */ -"; - -# Full brightness example #ISSILedBrightness1 = " -#0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C1-1 -> C1-16 */ -#0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C2-1 -> C2-16 */ -#0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C3-1 -> C3-16 */ -#0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C4-1 -> C4-16 */ -#0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C5-1 -> C5-16 */ -#0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C6-1 -> C6-16 */ -#0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C7-1 -> C7-16 */ -#0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C8-1 -> C8-16 */ -#0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C9-1 -> C9-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C1-1 -> C1-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C2-1 -> C2-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C3-1 -> C3-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C4-1 -> C4-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C5-1 -> C5-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C6-1 -> C6-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C7-1 -> C7-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C8-1 -> C8-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C9-1 -> C9-16 */ #"; +# Full brightness example +ISSILedBrightness1 = " +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C1-1 -> C1-16 */ +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C2-1 -> C2-16 */ +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C3-1 -> C3-16 */ +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C4-1 -> C4-16 */ +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C5-1 -> C5-16 */ +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C6-1 -> C6-16 */ +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C7-1 -> C7-16 */ +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C8-1 -> C8-16 */ +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C9-1 -> C9-16 */ +"; + From b1dec678233618542abbdc8f7fe896af3637be0a Mon Sep 17 00:00:00 2001 From: "Ryan S. Brown" Date: Sat, 6 Feb 2016 21:06:08 -0500 Subject: [PATCH 06/23] Ensure directories can only be made with printable characters In situations where `ls` colors directories incorrectly, the `$module` variable contains unprintable characters. This causes directories to be impossible to `cd` into normally, and is generally a pain. --- buildall.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/buildall.bash b/buildall.bash index 4f5aaa9..a8c393b 100755 --- a/buildall.bash +++ b/buildall.bash @@ -31,7 +31,8 @@ main() { # Create permutation directories # Then run cmake, and run each build permutation # Keeping track of how many builds failed/passed - for module in $scanModules; do + for mod in $scanModules; do + module=$(tr -dc "[:print:]" <<< "$mod") # Create directory, but do not error if it exists already mkdir -p build/$module cd build/$module From 75832a17b763eb7a894bfa9b95c589bc4f42ada6 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Sat, 6 Feb 2016 18:06:37 -0800 Subject: [PATCH 07/23] Initial code for MD1_1 - IC60 /w Single color LEDs - Requires a different matrix configuration so it's incompatible with the old IC60 layout --- Scan/MD1_1/defaultMap.kll | 134 ++++++++++++++++++++++++++++++ Scan/MD1_1/matrix.h | 56 +++++++++++++ Scan/MD1_1/pinout | 93 +++++++++++++++++++++ Scan/MD1_1/scan_loop.c | 168 ++++++++++++++++++++++++++++++++++++++ Scan/MD1_1/scan_loop.h | 48 +++++++++++ Scan/MD1_1/setup.cmake | 33 ++++++++ 6 files changed, 532 insertions(+) create mode 100644 Scan/MD1_1/defaultMap.kll create mode 100644 Scan/MD1_1/matrix.h create mode 100644 Scan/MD1_1/pinout create mode 100644 Scan/MD1_1/scan_loop.c create mode 100644 Scan/MD1_1/scan_loop.h create mode 100644 Scan/MD1_1/setup.cmake diff --git a/Scan/MD1_1/defaultMap.kll b/Scan/MD1_1/defaultMap.kll new file mode 100644 index 0000000..df51d82 --- /dev/null +++ b/Scan/MD1_1/defaultMap.kll @@ -0,0 +1,134 @@ +Name = MD1_1; +Version = 0.3d; +Author = "HaaTa (Jacob Alexander) 2014-2016"; +KLL = 0.3c; + +# Modified Date +Date = 2016-02-06; + + +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 + + +# Custom Action Examples + +# Example capability, prints to cli +action1 => CustomAction_action1_capability(); # No arguments + +# 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 ); + + + +# Defines available to the MD1_1 Scan Module + +# LED Default Enable Mask Override +# +# Each LED is represented by a single bit +# See (http://www.issi.com/WW/pdf/31FL3731C.pdf) for details +ISSILedMask1 = " + 0xFF, 0x00, /* C1-1 -> C1-16 */ + 0xFF, 0x00, /* C2-1 -> C2-16 */ + 0xFF, 0x00, /* C3-1 -> C3-16 */ + 0xFF, 0x00, /* C4-1 -> C4-16 */ + 0xFF, 0x00, /* C5-1 -> C5-16 */ + 0xFF, 0x00, /* C6-1 -> C6-16 */ + 0xFF, 0x00, /* C7-1 -> C7-16 */ + 0x7F, 0x00, /* C8-1 -> C8-16 */ + 0x00, 0x00, /* C9-1 -> C9-16 */ +"; + +# LED Brightness Override +# +# Each LED channel supports 256 levels (8-bit control) +# By default, LEDs are set to 0 brightness +#ISSILedBrightness1 = " +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C1-1 -> C1-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C2-1 -> C2-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C3-1 -> C3-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C4-1 -> C4-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C5-1 -> C5-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C6-1 -> C6-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C7-1 -> C7-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C8-1 -> C8-16 */ +#0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C9-1 -> C9-16 */ +#"; + +# Full brightness example +ISSILedBrightness1 = " +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C1-1 -> C1-16 */ +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C2-1 -> C2-16 */ +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C3-1 -> C3-16 */ +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C4-1 -> C4-16 */ +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C5-1 -> C5-16 */ +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C6-1 -> C6-16 */ +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C7-1 -> C7-16 */ +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C8-1 -> C8-16 */ +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C9-1 -> C9-16 */ +"; + diff --git a/Scan/MD1_1/matrix.h b/Scan/MD1_1/matrix.h new file mode 100644 index 0000000..ca33a52 --- /dev/null +++ b/Scan/MD1_1/matrix.h @@ -0,0 +1,56 @@ +/* Copyright (C) 2014-2016 by Jacob Alexander + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#pragma once + +// ----- Includes ----- + +// Project Includes +#include + + + +// ----- Matrix Definition ----- + +// 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 + +// MD1 +// +// Columns (Strobe) +// PTB0..3,16,17 +// PTC4,5 +// PTD0 +// +// Rows (Sense) +// PTD1..7 + +// Define Rows (Sense) and Columns (Strobes) +GPIO_Pin Matrix_cols[] = { gpio(C,0), gpio(C,1), gpio(C,2), gpio(C,3), gpio(C,4), gpio(C,5), gpio(C,6), gpio(C,7), 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) }; + +// Define type of scan matrix +Config Matrix_type = Config_Pulldown; + diff --git a/Scan/MD1_1/pinout b/Scan/MD1_1/pinout new file mode 100644 index 0000000..4b40fe9 --- /dev/null +++ b/Scan/MD1_1/pinout @@ -0,0 +1,93 @@ +Pin Usage +========= + +mk20dx128vlf5 + + ---- +|Keys| + ---- + +* Strobe (Columns) + +TODO + + +* Sense (Rows) + +PTD1 +PTD2 +PTD3 +PTD4 +PTD5 +PTD6 +PTD7 + + + --- +|I2C| + --- + +* IS31FL3731C + +PTB0 - SCL0 (add header pin, label as SCL0) +PTB1 - SDA0 (add header pin, label as SDA0) +PTB17 - INTB Chip 1 +PTB16 - SDB (tied to all Chips, hardware shutdown) + + + ----- +|Debug| + ----- + +* SWD + +PTA0 (Pull-down) +PTA3 (Pull-up) + +* LEDs + +PTA19 (LED only for PCB, not McHCK) (XTAL) + +* UARTs + +PTA1 - RX0 +PTA2 - TX0 + +* Tag Connect + +1 - Vdd +5 +2 - PTA3 / SWD_IO +3 - Vss / Gnd +4 - PTA0 / SWD_CLK +5 - +5V +6 - PTA2 / TRACE_SWO +7 - N/C +8 - PTA1 / JTAG_TDI +9 - N/C +10 - Reset_b + + + ------ +|Unused| + ------ + +* GPIO + +PTA1 (Not broken out on PCB, available on McHCK) (Pull-up) +PTA2 (") +PTA4 (Pull-up) +PTA18 (EXTAL) + +PTC0 +PTC1 +PTC2 +PTC3 +PTC6 +PTC7 + +* Analog + +ADC0_DP0 +ADC0_DM0 + + diff --git a/Scan/MD1_1/scan_loop.c b/Scan/MD1_1/scan_loop.c new file mode 100644 index 0000000..74218a0 --- /dev/null +++ b/Scan/MD1_1/scan_loop.c @@ -0,0 +1,168 @@ +/* Copyright (C) 2014,2016 by Jacob Alexander + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +// ----- Includes ----- + +// Compiler Includes +#include + +// Project Includes +#include +#include +#include +#include +#include +#include +#include + +// Local Includes +#include "scan_loop.h" + + + +// ----- Function Declarations ----- + +// ----- Variables ----- + +// Number of scans since the last USB send +uint16_t Scan_scanCount = 0; + + + +// ----- Functions ----- + +// Setup +inline void Scan_setup() +{ + // Setup GPIO pins for matrix scanning + Matrix_setup(); + + // Setup ISSI chip to control the leds + LED_setup(); + + // Reset scan count + Scan_scanCount = 0; +} + + +// Main Detection Loop +inline uint8_t Scan_loop() +{ + Matrix_scan( Scan_scanCount++ ); + + // Process any LED events + LED_scan(); + + return 0; +} + + +// Signal from Macro Module that all keys have been processed (that it knows about) +inline void Scan_finishedWithMacro( uint8_t sentKeys ) +{ +} + + +// Signal from Output Module that all keys have been processed (that it knows about) +inline void Scan_finishedWithOutput( uint8_t sentKeys ) +{ + // Reset scan loop indicator (resets each key debounce state) + // TODO should this occur after USB send or Macro processing? + Scan_scanCount = 0; +} + + + +// ----- Capabilities ----- + +// Custom capability examples +// Refer to kll.h in Macros/PartialMap for state and stateType information +void CustomAction_action1_capability( uint8_t state, uint8_t stateType, uint8_t *args ) +{ + // Display capability name + // XXX This is required for debug cli to give you a list of capabilities + if ( stateType == 0xFF && state == 0xFF ) + { + print("CustomAction_action1_capability()"); + return; + } + + // Prints Action1 info message to the debug cli + info_print("Action1"); +} + +uint8_t CustomAction_blockHold_storage = 0; +void CustomAction_blockHold_capability( uint8_t state, uint8_t stateType, uint8_t *args ) +{ + // Display capability name + if ( stateType == 0xFF && state == 0xFF ) + { + print("CustomAction_blockHold_capability(usbCode)"); + return; + } + + // Retrieve 8-bit argument + uint8_t key = args[0]; + + // We only care about normal keys + if ( stateType == 0x00 ) + { + // Block given key if we're in the "Press" or "Hold" state + if ( ( state == 0x01 || state == 0x02 ) + && CustomAction_blockHold_storage == 0 ) + { + CustomAction_blockHold_storage = key; + info_msg("Blocking Key: "); + printHex( key ); + print( NL ); + } + // Release if in the "Off" or "Release" state and we're blocking + else if ( ( state == 0x00 || state == 0x03 ) + && key == CustomAction_blockHold_storage ) + { + info_msg("Unblocking Key: "); + printHex( CustomAction_blockHold_storage ); + print( NL ); + CustomAction_blockHold_storage = 0; + } + } +} + +void CustomAction_blockKey_capability( uint8_t state, uint8_t stateType, uint8_t *args ) +{ + // Display capability name + if ( stateType == 0xFF && state == 0xFF ) + { + print("CustomAction_blockKey_capability(usbCode)"); + return; + } + + // Retrieve 8-bit argument + uint8_t key = args[0]; + + // If key is not blocked, process + if ( key != CustomAction_blockHold_storage ) + { + extern void Output_usbCodeSend_capability( uint8_t state, uint8_t stateType, uint8_t *args ); + Output_usbCodeSend_capability( state, stateType, &key ); + } +} + diff --git a/Scan/MD1_1/scan_loop.h b/Scan/MD1_1/scan_loop.h new file mode 100644 index 0000000..0c89838 --- /dev/null +++ b/Scan/MD1_1/scan_loop.h @@ -0,0 +1,48 @@ +/* Copyright (C) 2014-2015 by Jacob Alexander + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#pragma once + +// ----- Includes ----- + +// Compiler Includes +#include + + + +// ----- Functions ----- + +// Functions to be called by main.c +void Scan_setup( void ); +uint8_t Scan_loop( void ); + +// Call-backs +void Scan_finishedWithMacro( uint8_t sentKeys ); // Called by Macro Module +void Scan_finishedWithOutput( uint8_t sentKeys ); // Called by Output Module + + +// ----- Capabilities ----- + +// Example capabilities +void CustomAction_action1_capability( uint8_t state, uint8_t stateType, uint8_t *args ); +void CustomAction_blockHold_capability( uint8_t state, uint8_t stateType, uint8_t *args ); +void CustomAction_blockKey_capability( uint8_t state, uint8_t stateType, uint8_t *args ); + diff --git a/Scan/MD1_1/setup.cmake b/Scan/MD1_1/setup.cmake new file mode 100644 index 0000000..5ca7607 --- /dev/null +++ b/Scan/MD1_1/setup.cmake @@ -0,0 +1,33 @@ +###| CMake Kiibohd Controller Scan Module |### +# +# Written by Jacob Alexander in 2014,2016 for the Kiibohd Controller +# +# Released into the Public Domain +# +### + + +### +# Required Submodules +# + +AddModule ( Scan ISSILed ) +AddModule ( Scan MatrixARM ) + + +### +# Module C files +# + +set ( Module_SRCS + scan_loop.c +) + + +### +# Compiler Family Compatibility +# +set ( ModuleCompatibility + arm +) + From 5f530b524845293c6b8a4e553e98bf75b2b1ad57 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Mon, 8 Feb 2016 08:28:38 -0800 Subject: [PATCH 08/23] Update README.markdown --- README.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/README.markdown b/README.markdown index 9e0d5c4..a7802f9 100644 --- a/README.markdown +++ b/README.markdown @@ -84,6 +84,7 @@ Contact If you really need to get a hold of HaaTa, email is best: `haata@kiibohd.com` IRC is likely faster though. +`#input.club@irc.freenode.net` `#geekhack@irc.freenode.net` `#deskthority@irc.freenode.net` From 1fd19c48eac0d7fd8834aa91783385c2844dca9a Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Thu, 11 Feb 2016 22:56:25 -0800 Subject: [PATCH 09/23] Changed name from MD1_1 to MD1.1 --- Scan/{MD1_1 => MD1.1}/defaultMap.kll | 2 +- Scan/{MD1_1 => MD1.1}/matrix.h | 0 Scan/{MD1_1 => MD1.1}/pinout | 0 Scan/{MD1_1 => MD1.1}/scan_loop.c | 0 Scan/{MD1_1 => MD1.1}/scan_loop.h | 0 Scan/{MD1_1 => MD1.1}/setup.cmake | 0 6 files changed, 1 insertion(+), 1 deletion(-) rename Scan/{MD1_1 => MD1.1}/defaultMap.kll (99%) rename Scan/{MD1_1 => MD1.1}/matrix.h (100%) rename Scan/{MD1_1 => MD1.1}/pinout (100%) rename Scan/{MD1_1 => MD1.1}/scan_loop.c (100%) rename Scan/{MD1_1 => MD1.1}/scan_loop.h (100%) rename Scan/{MD1_1 => MD1.1}/setup.cmake (100%) diff --git a/Scan/MD1_1/defaultMap.kll b/Scan/MD1.1/defaultMap.kll similarity index 99% rename from Scan/MD1_1/defaultMap.kll rename to Scan/MD1.1/defaultMap.kll index df51d82..f60a4ed 100644 --- a/Scan/MD1_1/defaultMap.kll +++ b/Scan/MD1.1/defaultMap.kll @@ -1,4 +1,4 @@ -Name = MD1_1; +Name = MD1.1; Version = 0.3d; Author = "HaaTa (Jacob Alexander) 2014-2016"; KLL = 0.3c; diff --git a/Scan/MD1_1/matrix.h b/Scan/MD1.1/matrix.h similarity index 100% rename from Scan/MD1_1/matrix.h rename to Scan/MD1.1/matrix.h diff --git a/Scan/MD1_1/pinout b/Scan/MD1.1/pinout similarity index 100% rename from Scan/MD1_1/pinout rename to Scan/MD1.1/pinout diff --git a/Scan/MD1_1/scan_loop.c b/Scan/MD1.1/scan_loop.c similarity index 100% rename from Scan/MD1_1/scan_loop.c rename to Scan/MD1.1/scan_loop.c diff --git a/Scan/MD1_1/scan_loop.h b/Scan/MD1.1/scan_loop.h similarity index 100% rename from Scan/MD1_1/scan_loop.h rename to Scan/MD1.1/scan_loop.h diff --git a/Scan/MD1_1/setup.cmake b/Scan/MD1.1/setup.cmake similarity index 100% rename from Scan/MD1_1/setup.cmake rename to Scan/MD1.1/setup.cmake From 6687470ae7f9163353991d93136eb2c1da9b8e86 Mon Sep 17 00:00:00 2001 From: CryHam Date: Fri, 19 Feb 2016 18:10:25 +0100 Subject: [PATCH 10/23] Added support for ghosting matrices and code for elimination. To use define GHOST in matrix.h, see example in Scan/CK3 --- Scan/CK3/defaultMap.kll | 85 +++++++++++++++ Scan/CK3/matrix.h | 53 +++++++++ Scan/CK3/pinout | 88 +++++++++++++++ Scan/CK3/prototype.kll | 73 +++++++++++++ Scan/CK3/scan_loop.c | 204 +++++++++++++++++++++++++++++++++++ Scan/CK3/scan_loop.h | 48 +++++++++ Scan/CK3/setup.cmake | 32 ++++++ Scan/MatrixARM/matrix_scan.c | 120 ++++++++++++++++++++- Scan/MatrixARM/matrix_scan.h | 10 ++ 9 files changed, 712 insertions(+), 1 deletion(-) create mode 100644 Scan/CK3/defaultMap.kll create mode 100644 Scan/CK3/matrix.h create mode 100644 Scan/CK3/pinout create mode 100644 Scan/CK3/prototype.kll create mode 100644 Scan/CK3/scan_loop.c create mode 100644 Scan/CK3/scan_loop.h create mode 100644 Scan/CK3/setup.cmake diff --git a/Scan/CK3/defaultMap.kll b/Scan/CK3/defaultMap.kll new file mode 100644 index 0000000..d821d95 --- /dev/null +++ b/Scan/CK3/defaultMap.kll @@ -0,0 +1,85 @@ +Name = CK3; +Version = 0.3; +Author = "Crystal Hammer 2016"; +KLL = 0.3c; + +# Modified Date +Date = 2016-02-19; + + +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 + + +# Custom Action Examples + +# Example capability, prints to cli +action1 => CustomAction_action1_capability(); # No arguments + +# 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 ); + diff --git a/Scan/CK3/matrix.h b/Scan/CK3/matrix.h new file mode 100644 index 0000000..28bd3b0 --- /dev/null +++ b/Scan/CK3/matrix.h @@ -0,0 +1,53 @@ +/* Copyright (C) 2014-2015 by Jacob Alexander + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#pragma once + +// ----- Includes ----- + +// Project Includes +#include + + + +// ----- Matrix Definition ----- + +// 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 + +// +// 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) }; + +// Define type of scan matrix +Config Matrix_type = Config_Pulldown; + + +// define this if your matrix has ghosting (i.e. regular keyboard without diodes) +#define GHOST diff --git a/Scan/CK3/pinout b/Scan/CK3/pinout new file mode 100644 index 0000000..a72c0e6 --- /dev/null +++ b/Scan/CK3/pinout @@ -0,0 +1,88 @@ +Pin Usage +========= + +mk20dx128vlf5 + + ---- +|Keys| + ---- + +* Strobe (Columns) + +PTB0 +PTB1 +PTB2 +PTB3 +PTB16 +PTB17 +PTC4 +PTC5 +PTD0 + + +* Sense (Rows) + +PTD1 +PTD2 +PTD3 +PTD4 +PTD5 +PTD6 +PTD7 + + + ----- +|Debug| + ----- + +* SWD + +PTA0 (Pull-down) +PTA3 (Pull-up) + +* LEDs + +PTA19 (LED only for PCB, not McHCK) (XTAL) + +* UARTs + +PTA1 - RX0 +PTA2 - TX0 + +* Tag Connect + +1 - Vdd +5 +2 - PTA3 / SWD_IO +3 - Vss / Gnd +4 - PTA0 / SWD_CLK +5 - +5V +6 - PTA2 / TRACE_SWO +7 - N/C +8 - PTA1 / JTAG_TDI +9 - N/C +10 - Reset_b + + + ------ +|Unused| + ------ + +* GPIO + +PTA1 (Not broken out on PCB, available on McHCK) (Pull-up) +PTA2 (") +PTA4 (Pull-up) +PTA18 (EXTAL) + +PTC0 +PTC1 +PTC2 +PTC3 +PTC6 +PTC7 + +* Analog + +ADC0_DP0 +ADC0_DM0 + diff --git a/Scan/CK3/prototype.kll b/Scan/CK3/prototype.kll new file mode 100644 index 0000000..64fe862 --- /dev/null +++ b/Scan/CK3/prototype.kll @@ -0,0 +1,73 @@ +Name = MD1; +Version = 0.2; +Author = "HaaTa (Jacob Alexander) 2014"; +KLL = 0.3; + +# Modified Date +Date = 2014-09-14; + + +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"Tab"; +S0x0F : U"Q"; +S0x10 : U"W"; +S0x11 : U"E"; +S0x12 : U"R"; +S0x13 : U"T"; +S0x14 : U"Y"; +S0x15 : U"U"; +S0x16 : U"I"; +S0x17 : U"O"; +S0x18 : U"P"; +S0x19 : U"LBrace"; +S0x1A : U"RBrace"; +S0x1B : U"Backspace"; +S0x1C : U"Ctrl"; +S0x1D : U"A"; +S0x1E : U"S"; +S0x1F : U"D"; +S0x20 : U"F"; +S0x21 : U"G"; +S0x22 : U"H"; +S0x23 : U"J"; +S0x24 : U"K"; +S0x25 : U"L"; +S0x26 : U"Semicolon"; +S0x27 : U"Quote"; +S0x28 : U"Enter"; +S0x29 : U"LShift"; +S0x2A : U"Z"; +S0x2B : U"X"; +S0x2C : U"C"; +S0x2D : U"V"; +S0x2E : U"B"; +S0x2F : U"N"; +S0x30 : U"M"; +S0x31 : U"Comma"; +S0x32 : U"Period"; +S0x33 : U"Slash"; +S0x34 : U"RShift"; +S0x35 : U"Function1"; # Fun key +S0x36 : U"Function2"; # Left Blank Key +S0x37 : U"LAlt"; +S0x38 : U"LGui"; +S0x39 : U"Space"; +S0x3A : U"RGui"; +S0x3B : U"RAlt"; +S0x3C : U"Function3"; # Right Blank Key 1 +S0x3D : U"Function4"; # Right Blank Key 2 +S0x3E : U"BackTick"; + diff --git a/Scan/CK3/scan_loop.c b/Scan/CK3/scan_loop.c new file mode 100644 index 0000000..22d43c2 --- /dev/null +++ b/Scan/CK3/scan_loop.c @@ -0,0 +1,204 @@ +/* Copyright (C) 2014 by Jacob Alexander + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +// ----- Includes ----- + +// Compiler Includes +#include + +// Project Includes +#include +#include +#include +#include +#include + +// Local Includes +#include "scan_loop.h" + + + +// ----- Function Declarations ----- + +// CLI Functions +void cliFunc_echo( char* args ); + + + +// ----- Variables ----- + +// Scan Module command dictionary +CLIDict_Entry( echo, "Example command, echos the arguments." ); + +CLIDict_Def( scanCLIDict, "Scan Module Commands" ) = { + CLIDict_Item( echo ), + { 0, 0, 0 } // Null entry for dictionary end +}; + +// Number of scans since the last USB send +uint16_t Scan_scanCount = 0; + + + +// ----- Functions ----- + +// Setup +inline void Scan_setup() +{ + // Register Scan CLI dictionary + CLI_registerDictionary( scanCLIDict, scanCLIDictName ); + + // Setup GPIO pins for matrix scanning + Matrix_setup(); + + // Reset scan count + Scan_scanCount = 0; +} + + +// Main Detection Loop +inline uint8_t Scan_loop() +{ + Matrix_scan( Scan_scanCount++ ); + + return 0; +} + + +// Signal from Macro Module that all keys have been processed (that it knows about) +inline void Scan_finishedWithMacro( uint8_t sentKeys ) +{ +} + + +// Signal from Output Module that all keys have been processed (that it knows about) +inline void Scan_finishedWithOutput( uint8_t sentKeys ) +{ + // Reset scan loop indicator (resets each key debounce state) + // TODO should this occur after USB send or Macro processing? + Scan_scanCount = 0; +} + + + +// ----- Capabilities ----- + +// Custom capability examples +// Refer to kll.h in Macros/PartialMap for state and stateType information +void CustomAction_action1_capability( uint8_t state, uint8_t stateType, uint8_t *args ) +{ + // Display capability name + // XXX This is required for debug cli to give you a list of capabilities + if ( stateType == 0xFF && state == 0xFF ) + { + print("CustomAction_action1_capability()"); + return; + } + + // Prints Action1 info message to the debug cli + info_print("Action1"); +} + +uint8_t CustomAction_blockHold_storage = 0; +void CustomAction_blockHold_capability( uint8_t state, uint8_t stateType, uint8_t *args ) +{ + // Display capability name + if ( stateType == 0xFF && state == 0xFF ) + { + print("CustomAction_blockHold_capability(usbCode)"); + return; + } + + // Retrieve 8-bit argument + uint8_t key = args[0]; + + // We only care about normal keys + if ( stateType == 0x00 ) + { + // Block given key if we're in the "Press" or "Hold" state + if ( ( state == 0x01 || state == 0x02 ) + && CustomAction_blockHold_storage == 0 ) + { + CustomAction_blockHold_storage = key; + info_msg("Blocking Key: "); + printHex( key ); + print( NL ); + } + // Release if in the "Off" or "Release" state and we're blocking + else if ( ( state == 0x00 || state == 0x03 ) + && key == CustomAction_blockHold_storage ) + { + info_msg("Unblocking Key: "); + printHex( CustomAction_blockHold_storage ); + print( NL ); + CustomAction_blockHold_storage = 0; + } + } +} + +void CustomAction_blockKey_capability( uint8_t state, uint8_t stateType, uint8_t *args ) +{ + // Display capability name + if ( stateType == 0xFF && state == 0xFF ) + { + print("CustomAction_blockKey_capability(usbCode)"); + return; + } + + // Retrieve 8-bit argument + uint8_t key = args[0]; + + // If key is not blocked, process + if ( key != CustomAction_blockHold_storage ) + { + extern void Output_usbCodeSend_capability( uint8_t state, uint8_t stateType, uint8_t *args ); + Output_usbCodeSend_capability( state, stateType, &key ); + } +} + + + +// ----- CLI Command Functions ----- + +// XXX Just an example command showing how to parse arguments (more complex than generally needed) +void cliFunc_echo( char* args ) +{ + char* curArgs; + char* arg1Ptr; + char* arg2Ptr = args; + + // Parse args until a \0 is found + while ( 1 ) + { + print( NL ); // No \r\n by default after the command is entered + + curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list + CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); + + // Stop processing args if no more are found + if ( *arg1Ptr == '\0' ) + break; + + // Print out the arg + dPrint( arg1Ptr ); + } +} + diff --git a/Scan/CK3/scan_loop.h b/Scan/CK3/scan_loop.h new file mode 100644 index 0000000..0c89838 --- /dev/null +++ b/Scan/CK3/scan_loop.h @@ -0,0 +1,48 @@ +/* Copyright (C) 2014-2015 by Jacob Alexander + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#pragma once + +// ----- Includes ----- + +// Compiler Includes +#include + + + +// ----- Functions ----- + +// Functions to be called by main.c +void Scan_setup( void ); +uint8_t Scan_loop( void ); + +// Call-backs +void Scan_finishedWithMacro( uint8_t sentKeys ); // Called by Macro Module +void Scan_finishedWithOutput( uint8_t sentKeys ); // Called by Output Module + + +// ----- Capabilities ----- + +// Example capabilities +void CustomAction_action1_capability( uint8_t state, uint8_t stateType, uint8_t *args ); +void CustomAction_blockHold_capability( uint8_t state, uint8_t stateType, uint8_t *args ); +void CustomAction_blockKey_capability( uint8_t state, uint8_t stateType, uint8_t *args ); + diff --git a/Scan/CK3/setup.cmake b/Scan/CK3/setup.cmake new file mode 100644 index 0000000..d40a338 --- /dev/null +++ b/Scan/CK3/setup.cmake @@ -0,0 +1,32 @@ +###| CMake Kiibohd Controller Scan Module |### +# +# Written by Jacob Alexander in 2014 for the Kiibohd Controller +# +# Released into the Public Domain +# +### + + +### +# Required Submodules +# + +AddModule ( Scan MatrixARM ) + + +### +# Module C files +# + +set ( Module_SRCS + scan_loop.c +) + + +### +# Compiler Family Compatibility +# +set ( ModuleCompatibility + arm +) + diff --git a/Scan/MatrixARM/matrix_scan.c b/Scan/MatrixARM/matrix_scan.c index a9018df..03a4148 100644 --- a/Scan/MatrixARM/matrix_scan.c +++ b/Scan/MatrixARM/matrix_scan.c @@ -70,6 +70,15 @@ CLIDict_Def( matrixCLIDict, "Matrix Module Commands" ) = { // Debounce Array KeyState Matrix_scanArray[ Matrix_colsNum * Matrix_rowsNum ]; +// Ghost Arrays +#ifdef GHOST +KeyGhost Matrix_ghostArray[ Matrix_colsNum * Matrix_rowsNum ]; + +uint8_t col_use[Matrix_colsNum], row_use[Matrix_rowsNum]; // used count +uint8_t col_ghost[Matrix_colsNum], row_ghost[Matrix_rowsNum]; // marked as having ghost if 1 +#endif + + // Matrix debug flag - If set to 1, for each keypress the scan code is displayed in hex // If set to 2, for each key state change, the scan code is displayed along with the state uint8_t matrixDebugMode = 0; @@ -111,10 +120,17 @@ uint8_t Matrix_pin( GPIO_Pin gpio, Type type ) { case Type_StrobeOn: *GPIO_PSOR |= (1 << gpio.pin); + #ifdef GHOST + *GPIO_PDDR |= (1 << gpio.pin); // output + #endif break; case Type_StrobeOff: *GPIO_PCOR |= (1 << gpio.pin); + #ifdef GHOST + // Ghosting martix needs to put not used (off) strobes in high impedance state + *GPIO_PDDR &= ~(1 << gpio.pin); // input, high Z state + #endif break; case Type_StrobeSetup: @@ -206,6 +222,11 @@ void Matrix_setup() Matrix_scanArray[ item ].activeCount = 0; Matrix_scanArray[ item ].inactiveCount = DebounceDivThreshold_define; // Start at 'off' steady state Matrix_scanArray[ item ].prevDecisionTime = 0; + #ifdef GHOST + Matrix_ghostArray[ item ].prev = KeyState_Off; + Matrix_ghostArray[ item ].cur = KeyState_Off; + Matrix_ghostArray[ item ].saved = KeyState_Off; + #endif } // Clear scan stats counters @@ -372,12 +393,14 @@ void Matrix_scan( uint16_t scanNum ) erro_print("Matrix scan bug!! Report me!"); break; } - + // Update decision time state->prevDecisionTime = currentTime; // Send keystate to macro module + #ifndef GHOST Macro_keyState( key, state->curState ); + #endif // Matrix Debug, only if there is a state change if ( matrixDebugMode && state->curState != state->prevState ) @@ -403,6 +426,101 @@ void Matrix_scan( uint16_t scanNum ) Matrix_pin( Matrix_cols[ strobe ], Type_StrobeOff ); } + + // Matrix ghosting check and elimination + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . +#ifdef GHOST + // strobe = column, sense = row + + // Count (rows) use for columns + //print("C "); + for ( uint8_t col = 0; col < Matrix_colsNum; col++ ) + { + uint8_t used = 0; + for ( uint8_t row = 0; row < Matrix_rowsNum; row++ ) + { + uint8_t key = Matrix_colsNum * row + col; + KeyState *state = &Matrix_scanArray[ key ]; + if ( keyOn(state->curState) ) + used++; + } + //printInt8(used); + col_use[col] = used; + col_ghost[col] = 0; // clear + } + + // Count (columns) use for rows + //print(" R "); + for ( uint8_t row = 0; row < Matrix_rowsNum; row++ ) + { + uint8_t used = 0; + for ( uint8_t col = 0; col < Matrix_colsNum; col++ ) + { + uint8_t key = Matrix_colsNum * row + col; + KeyState *state = &Matrix_scanArray[ key ]; + if ( keyOn(state->curState) ) + used++; + } + //printInt8(used); + row_use[row] = used; + row_ghost[row] = 0; // clear + } + + // Check if matrix has ghost + // Happens when key is pressed and some other key is pressed in same row and another in same column + //print(" G "); + for ( uint8_t col = 0; col < Matrix_colsNum; col++ ) + { + for ( uint8_t row = 0; row < Matrix_rowsNum; row++ ) + { + uint8_t key = Matrix_colsNum * row + col; + KeyState *state = &Matrix_scanArray[ key ]; + if ( keyOn(state->curState) && col_use[col] >= 2 && row_use[row] >= 2 ) + { + // mark col and row as having ghost + col_ghost[col] = 1; + row_ghost[row] = 1; + //print(" "); printInt8(col); print(","); printInt8(row); + } + } + } + //print( NL ); + + // Send keys + for ( uint8_t col = 0; col < Matrix_colsNum; col++ ) + { + for ( uint8_t row = 0; row < Matrix_rowsNum; row++ ) + { + uint8_t key = Matrix_colsNum * row + col; + KeyState *state = &Matrix_scanArray[ key ]; + KeyGhost *st = &Matrix_ghostArray[ key ]; + + // col or row is ghosting (crossed) + uint8_t ghost = (col_ghost[col] > 0 || row_ghost[row] > 0) ? 1 : 0; + + st->prev = st->cur; // previous + // save state if no ghost or outside ghosted area + if ( ghost == 0 ) + st->saved = state->curState; // save state if no ghost + // final + // use saved state if ghosting, or current if not + st->cur = ghost > 0 ? st->saved : state->curState; + + // Send keystate to macro module + 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 ); + } + } +#endif + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + + // State Table Output Debug if ( matrixDebugStateCounter > 0 ) { diff --git a/Scan/MatrixARM/matrix_scan.h b/Scan/MatrixARM/matrix_scan.h index 810e6d9..ce09bf1 100644 --- a/Scan/MatrixARM/matrix_scan.h +++ b/Scan/MatrixARM/matrix_scan.h @@ -139,6 +139,16 @@ typedef struct KeyState { uint8_t prevDecisionTime; } __attribute__((packed)) KeyState; +// Ghost Element, after ghost detection/cancelation +typedef struct KeyGhost { + KeyPosition prev; + KeyPosition cur; + KeyPosition saved; // state before ghosting +} __attribute__((packed)) KeyGhost; + +// utility +inline uint8_t keyOn(/*KeyPosition*/uint8_t st) +{ return (st == KeyState_Press || st == KeyState_Hold) ? 1 : 0; } // ----- Functions ----- From 57a75851e29756ed36251b114e2b3b3630bb8121 Mon Sep 17 00:00:00 2001 From: CryHam Date: Sat, 20 Feb 2016 08:33:39 +0100 Subject: [PATCH 11/23] Minor styling fixes. Renamed define to GHOSTING_MATRIX. Deleted unused files from CK3. --- Scan/CK3/matrix.h | 5 +- Scan/CK3/pinout | 88 ------------------------------------ Scan/CK3/prototype.kll | 73 ------------------------------ Scan/MatrixARM/matrix_scan.c | 14 +++--- Scan/MatrixARM/matrix_scan.h | 6 ++- 5 files changed, 14 insertions(+), 172 deletions(-) delete mode 100644 Scan/CK3/pinout delete mode 100644 Scan/CK3/prototype.kll diff --git a/Scan/CK3/matrix.h b/Scan/CK3/matrix.h index 28bd3b0..1a2be2e 100644 --- a/Scan/CK3/matrix.h +++ b/Scan/CK3/matrix.h @@ -49,5 +49,6 @@ GPIO_Pin Matrix_rows[] = { gpio(D,1), gpio(D,2), gpio(D,3), gpio(D,4), gpio(D,5) Config Matrix_type = Config_Pulldown; -// define this if your matrix has ghosting (i.e. regular keyboard without diodes) -#define GHOST +// Define this if your matrix has ghosting (i.e. regular keyboard without diodes) +// this will enable the anti-ghosting code +#define GHOSTING_MATRIX diff --git a/Scan/CK3/pinout b/Scan/CK3/pinout deleted file mode 100644 index a72c0e6..0000000 --- a/Scan/CK3/pinout +++ /dev/null @@ -1,88 +0,0 @@ -Pin Usage -========= - -mk20dx128vlf5 - - ---- -|Keys| - ---- - -* Strobe (Columns) - -PTB0 -PTB1 -PTB2 -PTB3 -PTB16 -PTB17 -PTC4 -PTC5 -PTD0 - - -* Sense (Rows) - -PTD1 -PTD2 -PTD3 -PTD4 -PTD5 -PTD6 -PTD7 - - - ----- -|Debug| - ----- - -* SWD - -PTA0 (Pull-down) -PTA3 (Pull-up) - -* LEDs - -PTA19 (LED only for PCB, not McHCK) (XTAL) - -* UARTs - -PTA1 - RX0 -PTA2 - TX0 - -* Tag Connect - -1 - Vdd +5 -2 - PTA3 / SWD_IO -3 - Vss / Gnd -4 - PTA0 / SWD_CLK -5 - +5V -6 - PTA2 / TRACE_SWO -7 - N/C -8 - PTA1 / JTAG_TDI -9 - N/C -10 - Reset_b - - - ------ -|Unused| - ------ - -* GPIO - -PTA1 (Not broken out on PCB, available on McHCK) (Pull-up) -PTA2 (") -PTA4 (Pull-up) -PTA18 (EXTAL) - -PTC0 -PTC1 -PTC2 -PTC3 -PTC6 -PTC7 - -* Analog - -ADC0_DP0 -ADC0_DM0 - diff --git a/Scan/CK3/prototype.kll b/Scan/CK3/prototype.kll deleted file mode 100644 index 64fe862..0000000 --- a/Scan/CK3/prototype.kll +++ /dev/null @@ -1,73 +0,0 @@ -Name = MD1; -Version = 0.2; -Author = "HaaTa (Jacob Alexander) 2014"; -KLL = 0.3; - -# Modified Date -Date = 2014-09-14; - - -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"Tab"; -S0x0F : U"Q"; -S0x10 : U"W"; -S0x11 : U"E"; -S0x12 : U"R"; -S0x13 : U"T"; -S0x14 : U"Y"; -S0x15 : U"U"; -S0x16 : U"I"; -S0x17 : U"O"; -S0x18 : U"P"; -S0x19 : U"LBrace"; -S0x1A : U"RBrace"; -S0x1B : U"Backspace"; -S0x1C : U"Ctrl"; -S0x1D : U"A"; -S0x1E : U"S"; -S0x1F : U"D"; -S0x20 : U"F"; -S0x21 : U"G"; -S0x22 : U"H"; -S0x23 : U"J"; -S0x24 : U"K"; -S0x25 : U"L"; -S0x26 : U"Semicolon"; -S0x27 : U"Quote"; -S0x28 : U"Enter"; -S0x29 : U"LShift"; -S0x2A : U"Z"; -S0x2B : U"X"; -S0x2C : U"C"; -S0x2D : U"V"; -S0x2E : U"B"; -S0x2F : U"N"; -S0x30 : U"M"; -S0x31 : U"Comma"; -S0x32 : U"Period"; -S0x33 : U"Slash"; -S0x34 : U"RShift"; -S0x35 : U"Function1"; # Fun key -S0x36 : U"Function2"; # Left Blank Key -S0x37 : U"LAlt"; -S0x38 : U"LGui"; -S0x39 : U"Space"; -S0x3A : U"RGui"; -S0x3B : U"RAlt"; -S0x3C : U"Function3"; # Right Blank Key 1 -S0x3D : U"Function4"; # Right Blank Key 2 -S0x3E : U"BackTick"; - diff --git a/Scan/MatrixARM/matrix_scan.c b/Scan/MatrixARM/matrix_scan.c index 03a4148..90343fe 100644 --- a/Scan/MatrixARM/matrix_scan.c +++ b/Scan/MatrixARM/matrix_scan.c @@ -71,7 +71,7 @@ CLIDict_Def( matrixCLIDict, "Matrix Module Commands" ) = { KeyState Matrix_scanArray[ Matrix_colsNum * Matrix_rowsNum ]; // Ghost Arrays -#ifdef GHOST +#ifdef GHOSTING_MATRIX KeyGhost Matrix_ghostArray[ Matrix_colsNum * Matrix_rowsNum ]; uint8_t col_use[Matrix_colsNum], row_use[Matrix_rowsNum]; // used count @@ -120,14 +120,14 @@ uint8_t Matrix_pin( GPIO_Pin gpio, Type type ) { case Type_StrobeOn: *GPIO_PSOR |= (1 << gpio.pin); - #ifdef GHOST + #ifdef GHOSTING_MATRIX *GPIO_PDDR |= (1 << gpio.pin); // output #endif break; case Type_StrobeOff: *GPIO_PCOR |= (1 << gpio.pin); - #ifdef GHOST + #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 @@ -222,7 +222,7 @@ void Matrix_setup() Matrix_scanArray[ item ].activeCount = 0; Matrix_scanArray[ item ].inactiveCount = DebounceDivThreshold_define; // Start at 'off' steady state Matrix_scanArray[ item ].prevDecisionTime = 0; - #ifdef GHOST + #ifdef GHOSTING_MATRIX Matrix_ghostArray[ item ].prev = KeyState_Off; Matrix_ghostArray[ item ].cur = KeyState_Off; Matrix_ghostArray[ item ].saved = KeyState_Off; @@ -393,12 +393,12 @@ void Matrix_scan( uint16_t scanNum ) erro_print("Matrix scan bug!! Report me!"); break; } - + // Update decision time state->prevDecisionTime = currentTime; // Send keystate to macro module - #ifndef GHOST + #ifndef GHOSTING_MATRIX Macro_keyState( key, state->curState ); #endif @@ -429,7 +429,7 @@ void Matrix_scan( uint16_t scanNum ) // Matrix ghosting check and elimination // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . -#ifdef GHOST +#ifdef GHOSTING_MATRIX // strobe = column, sense = row // Count (rows) use for columns diff --git a/Scan/MatrixARM/matrix_scan.h b/Scan/MatrixARM/matrix_scan.h index ce09bf1..8b9cee7 100644 --- a/Scan/MatrixARM/matrix_scan.h +++ b/Scan/MatrixARM/matrix_scan.h @@ -146,9 +146,11 @@ typedef struct KeyGhost { KeyPosition saved; // state before ghosting } __attribute__((packed)) KeyGhost; -// utility +// utility inline uint8_t keyOn(/*KeyPosition*/uint8_t st) -{ return (st == KeyState_Press || st == KeyState_Hold) ? 1 : 0; } +{ + return (st == KeyState_Press || st == KeyState_Hold) ? 1 : 0; +} // ----- Functions ----- From 8dbba83942ec97f5ba74cfc8e9e4f884441525f4 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Sat, 20 Feb 2016 13:27:49 -0800 Subject: [PATCH 12/23] Debug code for interconnect cable debugging --- Scan/UARTConnect/connect_scan.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Scan/UARTConnect/connect_scan.c b/Scan/UARTConnect/connect_scan.c index 1d08777..55f6619 100644 --- a/Scan/UARTConnect/connect_scan.c +++ b/Scan/UARTConnect/connect_scan.c @@ -1139,6 +1139,7 @@ void Connect_scan() } // Limit how often we do cable checks + //uint32_t time_compare = 0x007; // Used for debugging cables -HaaTa uint32_t time_compare = 0x7FF; // Must be all 1's, 0x3FF is valid, 0x4FF is not uint32_t current_time = systick_millis_count; if ( Connect_lastCheck != current_time From e761960acaa5c83b8b68f0deae9232c9f4bcf11c Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Sun, 21 Feb 2016 14:19:52 -0800 Subject: [PATCH 13/23] Setting bootloader max power to 100 mA - This amount of current is guaranteed by the USB spec before enumeration - Generally the bootloader doesn't need nearly this much, but to be safe --- Bootloader/dfu.desc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Bootloader/dfu.desc.c b/Bootloader/dfu.desc.c index dc11fef..a0ce1f8 100644 --- a/Bootloader/dfu.desc.c +++ b/Bootloader/dfu.desc.c @@ -1,5 +1,5 @@ // Originally Generated from MCHCK Toolkit -/* Copyright (c) Jacob Alexander 2014-2015 +/* Copyright (c) Jacob Alexander 2014-2016 * * 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 @@ -38,7 +38,7 @@ static const struct usb_config_1 usb_config_1 = { .bConfigurationValue = 1, .iConfiguration = 0, .one = 1, - .bMaxPower = 100 + .bMaxPower = 50 }, .usb_function_0 = { .iface = { From 46765e85c57e19b89754f4f9c26c8f18b35148e5 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Sun, 21 Feb 2016 19:56:52 -0800 Subject: [PATCH 14/23] Adding dynamic USB power support - Each scan module now has a current change callback which passes the available current as a parameter - No longer attempts to use the max 500 mA immediately, starts with 100 mA then goes to 500 mA after enumeration - If enumeration fails due to bMaxPower of 500 mA, then attempt again at 100 mA (might also be possible to go even lower to 20 mA in certain cases) - Now working with the Apple Ipad (no over-power messages) - Fixed Wake-up behaviour on Apple Ipad (and likely other iOS devices) - More effecient set_feature/clear_feature handling (device handler) - Initial power handling via Interconnect (still needs work to get it more dynamic) --- Output/pjrcUSB/arm/usb_desc.c | 6 +- Output/pjrcUSB/arm/usb_desc.h | 4 +- Output/pjrcUSB/arm/usb_dev.c | 121 ++++++++++++++++++++++++++++++-- Output/pjrcUSB/arm/usb_dev.h | 1 + Output/pjrcUSB/output_com.c | 80 ++++++++++++++++++++- Output/pjrcUSB/output_com.h | 10 ++- Output/usbMuxUart/output_com.c | 80 ++++++++++++++++++++- Scan/ISSILed/led_scan.c | 30 +++++++- Scan/ISSILed/led_scan.h | 4 +- Scan/KType/scan_loop.c | 13 +++- Scan/KType/scan_loop.h | 8 ++- Scan/MD1.1/scan_loop.c | 12 +++- Scan/MD1.1/scan_loop.h | 4 +- Scan/MD1/scan_loop.c | 11 ++- Scan/MD1/scan_loop.h | 4 +- Scan/MDErgo1/scan_loop.c | 14 +++- Scan/MDErgo1/scan_loop.h | 8 ++- Scan/MatrixARM/matrix_scan.c | 25 ++++--- Scan/MatrixARM/matrix_scan.h | 4 +- Scan/STLcd/lcd_scan.c | 10 ++- Scan/STLcd/lcd_scan.h | 4 +- Scan/UARTConnect/connect_scan.c | 31 +++++++- Scan/UARTConnect/connect_scan.h | 4 +- Scan/WhiteFox/scan_loop.c | 12 +++- Scan/WhiteFox/scan_loop.h | 4 +- 25 files changed, 463 insertions(+), 41 deletions(-) diff --git a/Output/pjrcUSB/arm/usb_desc.c b/Output/pjrcUSB/arm/usb_desc.c index b7cb735..1d9a939 100644 --- a/Output/pjrcUSB/arm/usb_desc.c +++ b/Output/pjrcUSB/arm/usb_desc.c @@ -1,7 +1,7 @@ /* Teensyduino Core Library * http://www.pjrc.com/teensy/ * Copyright (c) 2013 PJRC.COM, LLC. - * Modified by Jacob Alexander (2013-2015) + * Modified by Jacob Alexander (2013-2016) * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -451,7 +451,7 @@ static uint8_t config_descriptor[CONFIG_DESC_SIZE] = { 1, // bConfigurationValue 0, // iConfiguration 0xA0, // bmAttributes - 250, // bMaxPower + 250, // bMaxPower - Entry Index 8 // --- Keyboard HID --- Boot Mode Keyboard Interface // - 9 bytes - @@ -695,6 +695,8 @@ static uint8_t config_descriptor[CONFIG_DESC_SIZE] = { SYS_CTRL_INTERVAL, // bInterval }; +uint8_t *usb_bMaxPower = &config_descriptor[8]; + // ----- String Descriptors ----- diff --git a/Output/pjrcUSB/arm/usb_desc.h b/Output/pjrcUSB/arm/usb_desc.h index 33c6589..0e769a1 100644 --- a/Output/pjrcUSB/arm/usb_desc.h +++ b/Output/pjrcUSB/arm/usb_desc.h @@ -1,7 +1,7 @@ /* Teensyduino Core Library * http://www.pjrc.com/teensy/ * Copyright (c) 2013 PJRC.COM, LLC. - * Modified by Jacob Alexander (2013-2015) + * Modified by Jacob Alexander (2013-2016) * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -137,3 +137,5 @@ extern const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS]; extern const usb_descriptor_list_t usb_descriptor_list[]; +extern uint8_t *usb_bMaxPower; + diff --git a/Output/pjrcUSB/arm/usb_dev.c b/Output/pjrcUSB/arm/usb_dev.c index 782f3ac..c0e4566 100644 --- a/Output/pjrcUSB/arm/usb_dev.c +++ b/Output/pjrcUSB/arm/usb_dev.c @@ -1,7 +1,7 @@ /* Teensyduino Core Library * http://www.pjrc.com/teensy/ * Copyright (c) 2013 PJRC.COM, LLC. - * Modifications by Jacob Alexander (2013-2015) + * Modifications by Jacob Alexander (2013-2016) * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -168,6 +168,9 @@ volatile uint8_t usb_reboot_timer = 0; static uint8_t reply_buffer[8]; +static uint8_t power_neg_delay; +static uint32_t power_neg_time; + // ----- Functions ----- @@ -188,6 +191,34 @@ static void endpoint0_transmit( const void *data, uint32_t len ) ep0_tx_bdt_bank ^= 1; } +// Used to check any USB state changes that may not have a proper interrupt +// Called once per scan loop, should take minimal processing time or it may affect other modules +void usb_device_check() +{ + // Check to see if we're still waiting for the next USB request after Get Configuration Descriptor + // If still waiting, restart the USB initialization with a lower power requirement + if ( power_neg_delay ) + { + // Check if 100 ms has elapsed + if ( systick_millis_count - power_neg_time > 100 ) + { + // Update bMaxPower + // The value set is in increments of 2 mA + // So 50 * 2 mA = 100 mA + // XXX Currently only transitions to 100 mA + // It may be possible to transition down again to 20 mA + *usb_bMaxPower = 50; + + // Re-initialize USB + power_neg_delay = 0; + usb_configuration = 0; // Clear USB configuration if we have one + USB0_CONTROL = 0; // Disable D+ Pullup to simulate disconnect + delay(10); // Delay is necessary to simulate disconnect + usb_init(); + } + } +} + static void usb_setup() { const uint8_t *data = NULL; @@ -199,6 +230,13 @@ static void usb_setup() const uint8_t *cfg; int i; + // If another request is made, disable the power negotiation check + // See GET_DESCRIPTOR - Configuration + if ( power_neg_delay ) + { + power_neg_delay = 0; + } + switch ( setup.wRequestAndType ) { case 0x0500: // SET_ADDRESS @@ -212,6 +250,10 @@ static void usb_setup() Output_Available = usb_configuration; reg = &USB0_ENDPT1; cfg = usb_endpoint_config_table; + + // Now configured so we can utilize bMaxPower now + Output_update_usb_current( *usb_bMaxPower * 2 ); + // clear all BDT entries, free any allocated memory... for ( i = 4; i < ( NUM_ENDPOINTS + 1) * 4; i++ ) { @@ -324,9 +366,27 @@ static void usb_setup() goto send; case 0x0100: // CLEAR_FEATURE (device) + switch ( setup.wValue ) + { + // CLEAR_FEATURE(DEVICE_REMOTE_WAKEUP) + // See SET_FEATURE(DEVICE_REMOTE_WAKEUP) for details + case 0x1: + goto send; + } + + warn_msg("SET_FEATURE - Device wValue("); + printHex( setup.wValue ); + print( ")" NL ); + endpoint0_stall(); + return; + case 0x0101: // CLEAR_FEATURE (interface) // TODO: Currently ignoring, perhaps useful? -HaaTa - warn_print("CLEAR_FEATURE - Device/Interface"); + warn_msg("CLEAR_FEATURE - Interface wValue("); + printHex( setup.wValue ); + print(") wIndex("); + printHex( setup.wIndex ); + print( ")" NL ); endpoint0_stall(); return; @@ -342,9 +402,30 @@ static void usb_setup() goto send; case 0x0300: // SET_FEATURE (device) + switch ( setup.wValue ) + { + // SET_FEATURE(DEVICE_REMOTE_WAKEUP) + // XXX: Only used to confirm Remote Wake + // Used on Mac OSX and Windows not on Linux + // Good post on the behaviour: + // http://community.silabs.com/t5/8-bit-MCU/Remote-wakeup-HID/m-p/74957#M30802 + case 0x1: + goto send; + } + + warn_msg("SET_FEATURE - Device wValue("); + printHex( setup.wValue ); + print( ")" NL ); + endpoint0_stall(); + return; + case 0x0301: // SET_FEATURE (interface) // TODO: Currently ignoring, perhaps useful? -HaaTa - warn_print("SET_FEATURE - Device/Interface"); + warn_msg("SET_FEATURE - Interface wValue("); + printHex( setup.wValue ); + print(") wIndex("); + printHex( setup.wIndex ); + print( ")" NL ); endpoint0_stall(); return; @@ -385,6 +466,27 @@ static void usb_setup() { datalen = list->length; } + + // XXX Power negotiation hack -HaaTa + // Some devices such as the Apple Ipad do not support bMaxPower greater than 100 mA + // However, there is no provision in the basic USB 2.0 stack for power negotiation + // To get around this: + // * Attempt to set bMaxPower to 500 mA first + // * If more than 100 ms passes since retrieving a Get Configuration Descriptor + // (Descriptor with bMaxPower in it) + // * Change usb_bMaxPower to 50 (100 mA) + // * Restart the USB init process + // According to notes online, it says that some Apple devices can only do 20 mA + // However, in my testing this hasn't been the case + // (you can also draw as much current as you want if you just lie in the descriptor :P) + // If this becomes an issue we can use this hack a second time to negotiate down to 20 mA + // (which should be fine for just the mcu) + if ( setup.wValue == 0x0200 && setup.wIndex == 0x0 ) + { + power_neg_delay = 1; + power_neg_time = systick_millis_count; + } + #if UART_DEBUG print("Desc found, "); printHex32( (uint32_t)data ); @@ -862,6 +964,11 @@ void usb_rx_memory( usb_packet_t *packet ) void usb_tx( uint32_t endpoint, usb_packet_t *packet ) { + // Since we are transmitting data, USB will be brought out of sleep/suspend + // if it's in that state + // Use the currently set descriptor value + Output_update_usb_current( *usb_bMaxPower * 2 ); + bdt_t *b = &table[ index( endpoint, TX, EVEN ) ]; uint8_t next; @@ -1161,9 +1268,12 @@ restart: USB0_ISTAT = USB_ISTAT_ERROR; } + // USB Host signalling device to enter 'sleep' state + // The USB Module triggers this interrupt when it detects the bus has been idle for 3 ms if ( (status & USB_ISTAT_SLEEP /* 10 */ ) ) { - //serial_print("sleep\n"); + info_print("Host has requested USB sleep/suspend state"); + Output_update_usb_current( 100 ); // Set to 100 mA USB0_ISTAT = USB_ISTAT_SLEEP; } } @@ -1220,6 +1330,9 @@ uint8_t usb_init() // enable d+ pullup USB0_CONTROL = USB_CONTROL_DPPULLUPNONOTG; + // Do not check for power negotiation delay until Get Configuration Descriptor + power_neg_delay = 0; + return 1; } diff --git a/Output/pjrcUSB/arm/usb_dev.h b/Output/pjrcUSB/arm/usb_dev.h index 0f445de..827f843 100644 --- a/Output/pjrcUSB/arm/usb_dev.h +++ b/Output/pjrcUSB/arm/usb_dev.h @@ -81,6 +81,7 @@ static inline uint32_t usb_rx_byte_count(uint32_t endpoint) } void usb_device_reload(); +void usb_device_check(); extern void usb_serial_flush_callback(); diff --git a/Output/pjrcUSB/output_com.c b/Output/pjrcUSB/output_com.c index 2e97e42..b18bbdb 100644 --- a/Output/pjrcUSB/output_com.c +++ b/Output/pjrcUSB/output_com.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2011-2015 by Jacob Alexander +/* Copyright (C) 2011-2016 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -137,6 +137,14 @@ volatile uint8_t Output_Available = 0; // 1 - Debug enabled uint8_t Output_DebugMode = 0; +// mA - Set by outside module if not using USB (i.e. Interconnect) +// Generally set to 100 mA (low power) or 500 mA (high power) +uint16_t Output_ExtCurrent_Available = 0; + +// mA - Set by USB module (if exists) +// Initially 100 mA, but may be negotiated higher (e.g. 500 mA) +uint16_t Output_USBCurrent_Available = 0; + // ----- Capabilities ----- @@ -535,6 +543,10 @@ inline void Output_setup() // USB Data Send inline void Output_send() { + // USB status checks + // Non-standard USB state manipulation, usually does nothing + usb_device_check(); + // Boot Mode Only, unset stale keys if ( USBKeys_Protocol == 0 ) for ( uint8_t c = USBKeys_Sent; c < USB_BOOT_MAX_KEYS; c++ ) @@ -614,6 +626,72 @@ inline void Output_softReset() } +// Update USB current (mA) +// Triggers power change event +void Output_update_usb_current( unsigned int current ) +{ + // Only signal if changed + if ( current == Output_USBCurrent_Available ) + return; + + // Update USB current + Output_USBCurrent_Available = current; + + unsigned int total_current = Output_current_available(); + info_msg("USB Available Current Changed. Total Available: "); + printInt32( total_current ); + print(" mA" NL); + + // Send new total current to the Scan Modules + Scan_currentChange( Output_current_available() ); +} + + +// Update external current (mA) +// Triggers power change event +void Output_update_external_current( unsigned int current ) +{ + // Only signal if changed + if ( current == Output_ExtCurrent_Available ) + return; + + // Update external current + Output_ExtCurrent_Available = current; + + unsigned int total_current = Output_current_available(); + info_msg("External Available Current Changed. Total Available: "); + printInt32( total_current ); + print(" mA" NL); + + // Send new total current to the Scan Modules + Scan_currentChange( Output_current_available() ); +} + + +// Power/Current Available +unsigned int Output_current_available() +{ + unsigned int total_current = 0; + + // Check for USB current source + total_current += Output_USBCurrent_Available; + + // Check for external current source + total_current += Output_ExtCurrent_Available; + + // XXX If the total available current is still 0 + // Set to 100 mA, which is generally a safe assumption at startup + // before we've been able to determine actual available current + if ( total_current == 0 ) + { + total_current = 100; + } + + return total_current; +} + + + // ----- CLI Command Functions ----- void cliFunc_kbdProtocol( char* args ) diff --git a/Output/pjrcUSB/output_com.h b/Output/pjrcUSB/output_com.h index c82ed98..2448683 100644 --- a/Output/pjrcUSB/output_com.h +++ b/Output/pjrcUSB/output_com.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2013-2015 by Jacob Alexander +/* Copyright (C) 2013-2016 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -82,6 +82,8 @@ extern volatile uint8_t Output_Available; // 0 - Output module not fully functi extern uint8_t Output_DebugMode; // 0 - Debug disabled, 1 - Debug enabled +extern uint16_t Output_ExtCurrent_Available; // mA - Set by outside module if not using USB (i.e. Interconnect) + // ----- Functions ----- @@ -97,6 +99,12 @@ void Output_softReset(); // Relies on USB serial module unsigned int Output_availablechar(); +// Returns the total mA available (total, if used in a chain, each device will have to use a slice of it) +unsigned int Output_current_available(); + +void Output_update_external_current( unsigned int current ); +void Output_update_usb_current( unsigned int current ); + int Output_getchar(); int Output_putchar( char c ); int Output_putstr( char* str ); diff --git a/Output/usbMuxUart/output_com.c b/Output/usbMuxUart/output_com.c index 44c5b49..55c9553 100644 --- a/Output/usbMuxUart/output_com.c +++ b/Output/usbMuxUart/output_com.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -143,6 +143,14 @@ volatile uint8_t Output_Available = 0; // 1 - Debug enabled uint8_t Output_DebugMode = 0; +// mA - Set by outside module if not using USB (i.e. Interconnect) +// Generally set to 100 mA (low power) or 500 mA (high power) +uint16_t Output_ExtCurrent_Available = 0; + +// mA - Set by USB module (if exists) +// Initially 100 mA, but may be negotiated higher (e.g. 500 mA) +uint16_t Output_USBCurrent_Available = 0; + // ----- Capabilities ----- @@ -544,6 +552,10 @@ inline void Output_setup() // USB Data Send inline void Output_send() { + // USB status checks + // Non-standard USB state manipulation, usually does nothing + usb_device_check(); + // Boot Mode Only, unset stale keys if ( USBKeys_Protocol == 0 ) for ( uint8_t c = USBKeys_Sent; c < USB_BOOT_MAX_KEYS; c++ ) @@ -641,6 +653,72 @@ inline void Output_softReset() } +// Update USB current (mA) +// Triggers power change event +void Output_update_usb_current( unsigned int current ) +{ + // Only signal if changed + if ( current == Output_USBCurrent_Available ) + return; + + // Update USB current + Output_USBCurrent_Available = current; + + unsigned int total_current = Output_current_available(); + info_msg("USB Available Current Changed. Total Available: "); + printInt32( total_current ); + print(" mA" NL); + + // Send new total current to the Scan Modules + Scan_currentChange( Output_current_available() ); +} + + +// Update external current (mA) +// Triggers power change event +void Output_update_external_current( unsigned int current ) +{ + // Only signal if changed + if ( current == Output_ExtCurrent_Available ) + return; + + // Update external current + Output_ExtCurrent_Available = current; + + unsigned int total_current = Output_current_available(); + info_msg("External Available Current Changed. Total Available: "); + printInt32( total_current ); + print(" mA" NL); + + // Send new total current to the Scan Modules + Scan_currentChange( Output_current_available() ); +} + + +// Power/Current Available +unsigned int Output_current_available() +{ + unsigned int total_current = 0; + + // Check for USB current source + total_current += Output_USBCurrent_Available; + + // Check for external current source + total_current += Output_ExtCurrent_Available; + + // XXX If the total available current is still 0 + // Set to 100 mA, which is generally a safe assumption at startup + // before we've been able to determine actual available current + if ( total_current == 0 ) + { + total_current = 100; + } + + return total_current; +} + + + // ----- CLI Command Functions ----- void cliFunc_kbdProtocol( char* args ) diff --git a/Scan/ISSILed/led_scan.c b/Scan/ISSILed/led_scan.c index 8a92b76..609f2d7 100644 --- a/Scan/ISSILed/led_scan.c +++ b/Scan/ISSILed/led_scan.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * This file is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -406,8 +406,14 @@ inline void LED_setup() // Set default brightness LED_sendPage( (uint8_t*)LED_defaultBrightness1, sizeof( LED_defaultBrightness1 ), 0 ); - // Disable Software shutdown of ISSI chip - LED_writeReg( 0x0A, 0x01, 0x0B ); + // Do not disable software shutdown of ISSI chip unless current is high enough + // Require at least 150 mA + // May be enabled/disabled at a later time + if ( Output_current_available() >= 150 ) + { + // Disable Software shutdown of ISSI chip + LED_writeReg( 0x0A, 0x01, 0x0B ); + } } @@ -644,6 +650,24 @@ inline uint8_t LED_scan() } +// Called by parent Scan Module whenver the available current has changed +// current - mA +void LED_currentChange( unsigned int current ) +{ + // TODO dim LEDs in low power mode instead of shutting off + if ( current < 150 ) + { + // Enabled Software shutdown of ISSI chip + LED_writeReg( 0x0A, 0x00, 0x0B ); + } + else + { + // Disable Software shutdown of ISSI chip + LED_writeReg( 0x0A, 0x01, 0x0B ); + } +} + + // ----- Capabilities ----- diff --git a/Scan/ISSILed/led_scan.h b/Scan/ISSILed/led_scan.h index 71d8e80..545b8b9 100644 --- a/Scan/ISSILed/led_scan.h +++ b/Scan/ISSILed/led_scan.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * This file is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,3 +28,5 @@ void LED_setup(); uint8_t LED_scan(); +void LED_currentChange( unsigned int current ); + diff --git a/Scan/KType/scan_loop.c b/Scan/KType/scan_loop.c index 7999853..4e52706 100644 --- a/Scan/KType/scan_loop.c +++ b/Scan/KType/scan_loop.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -97,3 +97,14 @@ inline void Scan_finishedWithOutput( uint8_t sentKeys ) Scan_scanCount = 0; } + +// Signal from the Output Module that the available current has changed +// current - mA +void Scan_currentChange( unsigned int current ) +{ + // Indicate to all submodules current change + Connect_currentChange( current ); + Matrix_currentChange( current ); + LED_currentChange( current ); +} + diff --git a/Scan/KType/scan_loop.h b/Scan/KType/scan_loop.h index 17a06fc..b18a0ca 100644 --- a/Scan/KType/scan_loop.h +++ b/Scan/KType/scan_loop.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -31,10 +31,12 @@ // ----- Functions ----- // Functions to be called by main.c -void Scan_setup( void ); -uint8_t Scan_loop( void ); +void Scan_setup(); +uint8_t Scan_loop(); // Call-backs void Scan_finishedWithMacro( uint8_t sentKeys ); // Called by Macro Module void Scan_finishedWithOutput( uint8_t sentKeys ); // Called by Output Module +void Scan_currentChange( unsigned int current ); // Called by Output Module + diff --git a/Scan/MD1.1/scan_loop.c b/Scan/MD1.1/scan_loop.c index 74218a0..3b2bad1 100644 --- a/Scan/MD1.1/scan_loop.c +++ b/Scan/MD1.1/scan_loop.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2014,2016 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -90,6 +90,16 @@ inline void Scan_finishedWithOutput( uint8_t sentKeys ) } +// Signal from the Output Module that the available current has changed +// current - mA +void Scan_currentChange( unsigned int current ) +{ + // Indicate to all submodules current change + Matrix_currentChange( current ); + LED_currentChange( current ); +} + + // ----- Capabilities ----- diff --git a/Scan/MD1.1/scan_loop.h b/Scan/MD1.1/scan_loop.h index 0c89838..339ede5 100644 --- a/Scan/MD1.1/scan_loop.h +++ b/Scan/MD1.1/scan_loop.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -38,6 +38,8 @@ uint8_t Scan_loop( void ); void Scan_finishedWithMacro( uint8_t sentKeys ); // Called by Macro Module void Scan_finishedWithOutput( uint8_t sentKeys ); // Called by Output Module +void Scan_currentChange( unsigned int current ); // Called by Output Module + // ----- Capabilities ----- diff --git a/Scan/MD1/scan_loop.c b/Scan/MD1/scan_loop.c index 22d43c2..d9348e1 100644 --- a/Scan/MD1/scan_loop.c +++ b/Scan/MD1/scan_loop.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -175,6 +175,15 @@ void CustomAction_blockKey_capability( uint8_t state, uint8_t stateType, uint8_t } +// Signal from the Output Module that the available current has changed +// current - mA +void Scan_currentChange( unsigned int current ) +{ + // Indicate to all submodules current change + Matrix_currentChange( current ); +} + + // ----- CLI Command Functions ----- diff --git a/Scan/MD1/scan_loop.h b/Scan/MD1/scan_loop.h index 0c89838..339ede5 100644 --- a/Scan/MD1/scan_loop.h +++ b/Scan/MD1/scan_loop.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -38,6 +38,8 @@ uint8_t Scan_loop( void ); void Scan_finishedWithMacro( uint8_t sentKeys ); // Called by Macro Module void Scan_finishedWithOutput( uint8_t sentKeys ); // Called by Output Module +void Scan_currentChange( unsigned int current ); // Called by Output Module + // ----- Capabilities ----- diff --git a/Scan/MDErgo1/scan_loop.c b/Scan/MDErgo1/scan_loop.c index d5e97e5..e80119b 100644 --- a/Scan/MDErgo1/scan_loop.c +++ b/Scan/MDErgo1/scan_loop.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -102,3 +102,15 @@ inline void Scan_finishedWithOutput( uint8_t sentKeys ) Scan_scanCount = 0; } + +// Signal from the Output Module that the available current has changed +// current - mA +void Scan_currentChange( unsigned int current ) +{ + // Indicate to all submodules current change + Connect_currentChange( current ); + Matrix_currentChange( current ); + LED_currentChange( current ); + LCD_currentChange( current ); +} + diff --git a/Scan/MDErgo1/scan_loop.h b/Scan/MDErgo1/scan_loop.h index 17a06fc..b18a0ca 100644 --- a/Scan/MDErgo1/scan_loop.h +++ b/Scan/MDErgo1/scan_loop.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -31,10 +31,12 @@ // ----- Functions ----- // Functions to be called by main.c -void Scan_setup( void ); -uint8_t Scan_loop( void ); +void Scan_setup(); +uint8_t Scan_loop(); // Call-backs void Scan_finishedWithMacro( uint8_t sentKeys ); // Called by Macro Module void Scan_finishedWithOutput( uint8_t sentKeys ); // Called by Output Module +void Scan_currentChange( unsigned int current ); // Called by Output Module + diff --git a/Scan/MatrixARM/matrix_scan.c b/Scan/MatrixARM/matrix_scan.c index 90343fe..017161d 100644 --- a/Scan/MatrixARM/matrix_scan.c +++ b/Scan/MatrixARM/matrix_scan.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -428,7 +428,7 @@ void Matrix_scan( uint16_t scanNum ) // Matrix ghosting check and elimination - // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . #ifdef GHOSTING_MATRIX // strobe = column, sense = row @@ -465,7 +465,7 @@ void Matrix_scan( uint16_t scanNum ) row_use[row] = used; row_ghost[row] = 0; // clear } - + // Check if matrix has ghost // Happens when key is pressed and some other key is pressed in same row and another in same column //print(" G "); @@ -494,10 +494,10 @@ void Matrix_scan( uint16_t scanNum ) uint8_t key = Matrix_colsNum * row + col; KeyState *state = &Matrix_scanArray[ key ]; KeyGhost *st = &Matrix_ghostArray[ key ]; - + // col or row is ghosting (crossed) uint8_t ghost = (col_ghost[col] > 0 || row_ghost[row] > 0) ? 1 : 0; - + st->prev = st->cur; // previous // save state if no ghost or outside ghosted area if ( ghost == 0 ) @@ -505,9 +505,9 @@ void Matrix_scan( uint16_t scanNum ) // final // use saved state if ghosting, or current if not st->cur = ghost > 0 ? st->saved : state->curState; - + // Send keystate to macro module - KeyPosition k = !st->cur + 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 @@ -518,7 +518,7 @@ void Matrix_scan( uint16_t scanNum ) } } #endif - // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . // State Table Output Debug @@ -567,6 +567,15 @@ void Matrix_scan( uint16_t scanNum ) } +// Called by parent scan module whenever the available current changes +// current - mA +void Matrix_currentChange( unsigned int current ) +{ + // TODO - Any potential power savings? +} + + + // ----- CLI Command Functions ----- void cliFunc_matrixDebug ( char* args ) diff --git a/Scan/MatrixARM/matrix_scan.h b/Scan/MatrixARM/matrix_scan.h index 8b9cee7..3a8f0e2 100644 --- a/Scan/MatrixARM/matrix_scan.h +++ b/Scan/MatrixARM/matrix_scan.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -158,3 +158,5 @@ inline uint8_t keyOn(/*KeyPosition*/uint8_t st) void Matrix_setup(); void Matrix_scan( uint16_t scanNum ); +void Matrix_currentChange( unsigned int current ); + diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index c4bf080..1dd9126 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 by Jacob Alexander +/* Copyright (C) 2015-2016 by Jacob Alexander * * This file is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -346,6 +346,14 @@ inline uint8_t LCD_scan() } +// Signal from parent Scan Module that available current has changed +// current - mA +void LCD_currentChange( unsigned int current ) +{ + // TODO - Power savings? +} + + // ----- Capabilities ----- diff --git a/Scan/STLcd/lcd_scan.h b/Scan/STLcd/lcd_scan.h index 36884a2..096107b 100644 --- a/Scan/STLcd/lcd_scan.h +++ b/Scan/STLcd/lcd_scan.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 by Jacob Alexander +/* Copyright (C) 2015-2016 by Jacob Alexander * * This file is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,3 +28,5 @@ void LCD_setup(); uint8_t LCD_scan(); +void LCD_currentChange( unsigned int current ); + diff --git a/Scan/UARTConnect/connect_scan.c b/Scan/UARTConnect/connect_scan.c index 55f6619..4c56c3c 100644 --- a/Scan/UARTConnect/connect_scan.c +++ b/Scan/UARTConnect/connect_scan.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * This file is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -470,6 +470,14 @@ uint8_t Connect_receive_CableCheck( uint8_t byte, uint16_t *pending_bytes, uint8 } else { + // Lower current requirement during errors + // USB minimum + // Only if this is not the master node + if ( Connect_id != 0 ) + { + Output_update_external_current( 100 ); + } + Connect_cableFaultsMaster++; Connect_cableOkMaster = 0; print(" Master "); @@ -489,6 +497,12 @@ uint8_t Connect_receive_CableCheck( uint8_t byte, uint16_t *pending_bytes, uint8 } else { + // If we already have an Id, then set max current again + if ( Connect_id != 255 && Connect_id != 0 ) + { + // TODO reset to original negotiated current + Output_update_external_current( 500 ); + } Connect_cableChecksMaster++; } } @@ -560,6 +574,14 @@ uint8_t Connect_receive_IdEnumeration( uint8_t id, uint16_t *pending_bytes, uint // Send reponse back to master Connect_send_IdReport( id ); + // Node now enumerated, set external power to USB Max + // Only set if this is not the master node + // TODO Determine power slice for each node as part of protocol + if ( Connect_id != 0 ) + { + Output_update_external_current( 500 ); + } + // Propogate next Id if the connection is ok if ( Connect_cableOkSlave ) { @@ -1177,6 +1199,13 @@ void Connect_scan() } +// Called by parent Scan module whenever the available current changes +void Connect_currentChange( unsigned int current ) +{ + // TODO - Any potential power saving here? +} + + // ----- CLI Command Functions ----- diff --git a/Scan/UARTConnect/connect_scan.h b/Scan/UARTConnect/connect_scan.h index cdd7ed0..1d87dfd 100644 --- a/Scan/UARTConnect/connect_scan.h +++ b/Scan/UARTConnect/connect_scan.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * This file is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -167,3 +167,5 @@ void Connect_scan(); void Connect_send_ScanCode( uint8_t id, TriggerGuide *scanCodeStateList, uint8_t numScanCodes ); void Connect_send_RemoteCapability( uint8_t id, uint8_t capabilityIndex, uint8_t state, uint8_t stateType, uint8_t numArgs, uint8_t *args ); +void Connect_currentChange( unsigned int current ); + diff --git a/Scan/WhiteFox/scan_loop.c b/Scan/WhiteFox/scan_loop.c index 16cefa2..56fa995 100644 --- a/Scan/WhiteFox/scan_loop.c +++ b/Scan/WhiteFox/scan_loop.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -90,3 +90,13 @@ inline void Scan_finishedWithOutput( uint8_t sentKeys ) Scan_scanCount = 0; } + +// Signal from the Output Module that the available current has changed +// current - mA +void Scan_currentChange( unsigned int current ) +{ + // Indicate to all submodules current change + Matrix_currentChange( current ); + LED_currentChange( current ); +} + diff --git a/Scan/WhiteFox/scan_loop.h b/Scan/WhiteFox/scan_loop.h index 17a06fc..9e9a8f1 100644 --- a/Scan/WhiteFox/scan_loop.h +++ b/Scan/WhiteFox/scan_loop.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -38,3 +38,5 @@ uint8_t Scan_loop( void ); void Scan_finishedWithMacro( uint8_t sentKeys ); // Called by Macro Module void Scan_finishedWithOutput( uint8_t sentKeys ); // Called by Output Module +void Scan_currentChange( unsigned int current ); // Called by Output Module + From f57e069bb9d00b8bf59c2388a922a85d2e30ec66 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Tue, 23 Feb 2016 14:35:08 -0800 Subject: [PATCH 15/23] As per request of original author, updating license to MIT --- Scan/DPH/scan_loop.c | 29 +++++++++++++++++------------ Scan/DPH/scan_loop.h | 25 +++++++++++++++---------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/Scan/DPH/scan_loop.c b/Scan/DPH/scan_loop.c index 1a0176c..5d8d832 100644 --- a/Scan/DPH/scan_loop.c +++ b/Scan/DPH/scan_loop.c @@ -1,18 +1,23 @@ -/* Copyright (C) 2011-2013 by Joseph Makuch - * Additions by Jacob Alexander (2013-2014) +/* Copyright (C) 2011-2013 by Joseph Makuch (jmakuch+f@gmail.com) + * Additions by Jacob Alexander (2013-2014) (haata@kiibohd.com) * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3.0 of the License, or (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library 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 - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ // ----- Includes ----- diff --git a/Scan/DPH/scan_loop.h b/Scan/DPH/scan_loop.h index 83a9a1b..234b959 100644 --- a/Scan/DPH/scan_loop.h +++ b/Scan/DPH/scan_loop.h @@ -1,17 +1,22 @@ /* Copyright (C) 2013-2015 by Jacob Alexander * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3.0 of the License, or (at your option) any later version. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library 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 - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ #pragma once From 88670ac72f51e5f1f68b72ca300bdb0c999a37f7 Mon Sep 17 00:00:00 2001 From: CryHam Date: Tue, 1 Mar 2016 19:38:43 +0100 Subject: [PATCH 16/23] Changed CK3 matrix scan to Config_Pullup, inverted rows and columns Added STROBE_DELAY define in matrix.h All keys scan codes now in defaultMap.kll --- Scan/CK3/defaultMap.kll | 193 ++++++++++++++++++++++------------- Scan/CK3/matrix.h | 46 ++++++--- Scan/MatrixARM/matrix_scan.c | 34 ++++-- 3 files changed, 177 insertions(+), 96 deletions(-) diff --git a/Scan/CK3/defaultMap.kll b/Scan/CK3/defaultMap.kll index d821d95..30de5d0 100644 --- a/Scan/CK3/defaultMap.kll +++ b/Scan/CK3/defaultMap.kll @@ -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"; -# Custom Action Examples +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"; -# Example capability, prints to cli -action1 => CustomAction_action1_capability(); # No arguments +# 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"; -# 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 ); +# middle right column, custom +S0x8A : U"Esc"; +S0x89 : U"Backspace"; +S0x77 : U"Enter"; +S0x78 : U"RShift"; +# 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."; diff --git a/Scan/CK3/matrix.h b/Scan/CK3/matrix.h index 1a2be2e..7f6632d 100644 --- a/Scan/CK3/matrix.h +++ b/Scan/CK3/matrix.h @@ -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 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 diff --git a/Scan/MatrixARM/matrix_scan.c b/Scan/MatrixARM/matrix_scan.c index 90343fe..6693143 100644 --- a/Scan/MatrixARM/matrix_scan.c +++ b/Scan/MatrixARM/matrix_scan.c @@ -30,6 +30,7 @@ #include #include #include +#include // Local Includes #include "matrix_scan.h" @@ -110,7 +111,9 @@ uint8_t Matrix_pin( GPIO_Pin gpio, Type type ) // 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 @@ uint8_t Matrix_pin( GPIO_Pin gpio, Type type ) switch ( type ) { case Type_StrobeOn: - *GPIO_PSOR |= (1 << gpio.pin); #ifdef GHOSTING_MATRIX - *GPIO_PDDR |= (1 << gpio.pin); // output + *GPIO_PCOR |= (1 << gpio.pin); + *GPIO_PDDR |= (1 << gpio.pin); // output, low + #else + *GPIO_PSOR |= (1 << gpio.pin); #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 @@ uint8_t Matrix_pin( GPIO_Pin gpio, Type type ) 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 @@ void Matrix_scan( uint16_t scanNum ) // 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 @@ void Matrix_scan( uint16_t scanNum ) 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 ); } } From 602b48253870caf8523598097fd55150aa0e8080 Mon Sep 17 00:00:00 2001 From: CryHam Date: Tue, 1 Mar 2016 21:00:23 +0100 Subject: [PATCH 17/23] Updated CK3 with Scan_currentChange (copy from MD1). --- Scan/CK3/scan_loop.c | 9 +++++++++ Scan/CK3/scan_loop.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/Scan/CK3/scan_loop.c b/Scan/CK3/scan_loop.c index 22d43c2..b4c8c99 100644 --- a/Scan/CK3/scan_loop.c +++ b/Scan/CK3/scan_loop.c @@ -175,6 +175,15 @@ void CustomAction_blockKey_capability( uint8_t state, uint8_t stateType, uint8_t } +// Signal from the Output Module that the available current has changed +// current - mA +void Scan_currentChange( unsigned int current ) +{ + // Indicate to all submodules current change + Matrix_currentChange( current ); +} + + // ----- CLI Command Functions ----- diff --git a/Scan/CK3/scan_loop.h b/Scan/CK3/scan_loop.h index 0c89838..3c543ea 100644 --- a/Scan/CK3/scan_loop.h +++ b/Scan/CK3/scan_loop.h @@ -38,6 +38,8 @@ uint8_t Scan_loop( void ); void Scan_finishedWithMacro( uint8_t sentKeys ); // Called by Macro Module void Scan_finishedWithOutput( uint8_t sentKeys ); // Called by Output Module +void Scan_currentChange( unsigned int current ); // Called by Output Module + // ----- Capabilities ----- From 074134c47442fa28559598209e3d7d3f30326177 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Tue, 1 Mar 2016 19:35:21 -0800 Subject: [PATCH 18/23] Fixing potential WF LED issue - Added fix for USB Current Change * If called during interrupt, could hang the I2C bus * Delaying I2C writes till scan loop --- Scan/ISSILed/led_scan.c | 33 +++++++++++++++++++-------------- Scan/WhiteFox/defaultMap.kll | 4 ++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Scan/ISSILed/led_scan.c b/Scan/ISSILed/led_scan.c index 609f2d7..a091b86 100644 --- a/Scan/ISSILed/led_scan.c +++ b/Scan/ISSILed/led_scan.c @@ -639,12 +639,26 @@ uint8_t I2C_Send( uint8_t *data, uint8_t sendLen, uint8_t recvLen ) // LED State processing loop +unsigned int LED_currentEvent = 0; inline uint8_t LED_scan() { + // Check for current change event + if ( LED_currentEvent ) + { + // TODO dim LEDs in low power mode instead of shutting off + if ( LED_currentEvent < 150 ) + { + // Enable Software shutdown of ISSI chip + LED_writeReg( 0x0A, 0x00, 0x0B ); + } + else + { + // Disable Software shutdown of ISSI chip + LED_writeReg( 0x0A, 0x01, 0x0B ); + } - // I2C Busy - // S & I2C_S_BUSY - //I2C_S_BUSY + LED_currentEvent = 0; + } return 0; } @@ -654,17 +668,8 @@ inline uint8_t LED_scan() // current - mA void LED_currentChange( unsigned int current ) { - // TODO dim LEDs in low power mode instead of shutting off - if ( current < 150 ) - { - // Enabled Software shutdown of ISSI chip - LED_writeReg( 0x0A, 0x00, 0x0B ); - } - else - { - // Disable Software shutdown of ISSI chip - LED_writeReg( 0x0A, 0x01, 0x0B ); - } + // Delay action till next LED scan loop (as this callback sometimes occurs during interrupt requests) + LED_currentEvent = current; } diff --git a/Scan/WhiteFox/defaultMap.kll b/Scan/WhiteFox/defaultMap.kll index 6a4e641..037319b 100644 --- a/Scan/WhiteFox/defaultMap.kll +++ b/Scan/WhiteFox/defaultMap.kll @@ -95,7 +95,7 @@ ISSILedMask1 = " 0xFF, 0x00, /* C6-1 -> C6-16 */ 0xFF, 0x00, /* C7-1 -> C7-16 */ 0xFF, 0x00, /* C8-1 -> C8-16 */ - 0xFE, 0x00, /* C9-1 -> C9-16 */ + 0xFF, 0x00, /* C9-1 -> C9-16 */ "; # LED Brightness Override @@ -124,6 +124,6 @@ ISSILedBrightness1 = " 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C6-1 -> C6-16 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C7-1 -> C7-16 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C8-1 -> C8-16 */ -0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C9-1 -> C9-16 */ +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* C9-1 -> C9-16 */ "; From c5aed6cb17124b09939ca7037c288e517a66918f Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Thu, 3 Mar 2016 20:40:01 -0800 Subject: [PATCH 19/23] Adding convenience symlinks to the udev rules --- 98-kiibohd.rules | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/98-kiibohd.rules b/98-kiibohd.rules index d00a8b2..955bc13 100644 --- a/98-kiibohd.rules +++ b/98-kiibohd.rules @@ -3,9 +3,9 @@ ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", ENV{ID_MM_DEVICE_IGNORE}= ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", ENV{MTP_NO_PROBE}="1" SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", MODE:="0666" # Kiibohd Serial Interface -KERNEL=="ttyACM*", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", MODE:="0666" -KERNEL=="ttyACM*", ATTRS{idVendor}=="1c11", ATTRS{idProduct}=="b04d", MODE:="0666" -KERNEL=="ttyACM*", ATTRS{idVendor}=="1c11", ATTRS{idProduct}=="f05c", MODE:="0666" +KERNEL=="ttyACM*", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", SYMLINK+="kiibohd", MODE:="0666", +KERNEL=="ttyACM*", ATTRS{idVendor}=="1c11", ATTRS{idProduct}=="b04d", SYMLINK+="kiibohd", MODE:="0666" +KERNEL=="ttyACM*", ATTRS{idVendor}=="1c11", ATTRS{idProduct}=="f05c", SYMLINK+="kiibohd", MODE:="0666" # Kiibohd Device SUBSYSTEMS=="usb", ATTRS{idVendor}=="1c11", ATTRS{idProduct}=="b04d", MODE:="0666" # DFU Bootloader (MCHCK) @@ -16,4 +16,6 @@ SUBSYSTEMS=="usb", ATTRS{idVendor}=="2323", ATTRS{idProduct}=="0001", MODE:="066 ATTRS{idVendor}=="1C11", ATTRS{idProduct}=="b007", ENV{ID_MM_DEVICE_IGNORE}="1" ATTRS{idVendor}=="1C11", ATTRS{idProduct}=="b007", ENV{MTP_NO_PROBE}="1" SUBSYSTEMS=="usb", ATTRS{idVendor}=="1c11", ATTRS{idProduct}=="b007", MODE:="0666" +# Kiibohd Force Gauge +SUBSYSTEM=="tty", ATTRS{idVendor}=="1c11", ATTRS{idProduct}=="f05c", GROUP="users", MODE="0666", SYMLINK+="force" From 0102d05c8698a33c18b997fe166ca19fa358253e Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Fri, 4 Mar 2016 00:23:48 -0800 Subject: [PATCH 20/23] Fixing clang compilation and supporting clang-tidy - clang.c includes necessary functions to make clang compiler work (tested on teensy 3.1) - Added support code to generate a compile_commands.json for clang-tidy * Updates the symlink whenever cmake or make is called (Unix OSs only) --- .clang-tidy | 16 ++++++++++++ .gitignore | 1 + CMakeLists.txt | 18 ++++++++----- Lib/CMake/arm.cmake | 9 ++++++- Lib/CMake/build.cmake | 20 ++++++++++++++ Lib/clang.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 .clang-tidy create mode 100644 Lib/clang.c diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..8ae1316 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,16 @@ +--- +Checks: 'clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*' +HeaderFilterRegex: '' +AnalyzeTemporaryDtors: false +User: hyatt +CheckOptions: + - key: google-readability-braces-around-statements.ShortStatementLines + value: '1' + - key: google-readability-function-size.StatementThreshold + value: '800' + - key: google-readability-namespace-comments.ShortNamespaceLines + value: '10' + - key: google-readability-namespace-comments.SpacesBeforeComments + value: '2' +... + diff --git a/.gitignore b/.gitignore index 7a86e68..574420d 100644 --- a/.gitignore +++ b/.gitignore @@ -56,6 +56,7 @@ tags CMakeFiles CMakeCache.txt cmake_install.cmake +compile_commands.json # External Repos # ################## diff --git a/CMakeLists.txt b/CMakeLists.txt index dcb0c94..ec9fb62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ ###| CMAKE Kiibohd Controller |### # -# Jacob Alexander 2011-2015 +# Jacob Alexander 2011-2016 # Due to this file's usefulness: # # Released into the Public Domain @@ -25,7 +25,8 @@ set( CHIP "mk20dx128vlf5" # McHCK mk20dx128vlf5 # "mk20dx256" # Teensy 3.1,3.2 (arm) # "mk20dx256vlh7" # Kiibohd-dfu mk20dx256vlh7 - CACHE STRING "Microcontroller Chip" ) + CACHE STRING "Microcontroller Chip" +) @@ -33,13 +34,14 @@ set( CHIP # Compiler Selection # -#| *** EXPERIMENTAL *** -#| Stick with gcc unless you know what you're doing +#| gcc has been tested much more (and will likely give smaller binaries) +#| clang does work though #| Currently only arm is supported with clang set( COMPILER "gcc" # arm-none-eabi-gcc / avr-gcc - Default # "clang" # arm-none-eabi - CACHE STRING "Compiler Type" ) + CACHE STRING "Compiler Type" +) @@ -72,11 +74,13 @@ set( MacroModule "PartialMap" ##| Sends the current list of usb key codes through USB HID set( OutputModule "pjrcUSB" - CACHE STRING "Output Module" ) + CACHE STRING "Output Module" +) ##| Debugging source to use, each module has it's own set of defines that it sets set( DebugModule "full" - CACHE STRING "Debug Module" ) + CACHE STRING "Debug Module" +) diff --git a/Lib/CMake/arm.cmake b/Lib/CMake/arm.cmake index be04de2..31fe0cd 100644 --- a/Lib/CMake/arm.cmake +++ b/Lib/CMake/arm.cmake @@ -1,6 +1,6 @@ ###| CMAKE Kiibohd Controller |### # -# Jacob Alexander 2011-2014 +# Jacob Alexander 2011-2016 # Due to this file's usefulness: # # Released into the Public Domain @@ -111,6 +111,13 @@ set( COMPILER_SRCS Lib/delay.c ) +#| Clang needs a few more functions for linking +if ( "${COMPILER}" MATCHES "clang" ) + set( COMPILER_SRCS ${COMPILER_SRCS} + Lib/clang.c + ) +endif () + message( STATUS "Compiler Source Files:" ) message( "${COMPILER_SRCS}" ) diff --git a/Lib/CMake/build.cmake b/Lib/CMake/build.cmake index b3209bf..de58ea0 100644 --- a/Lib/CMake/build.cmake +++ b/Lib/CMake/build.cmake @@ -135,3 +135,23 @@ elseif ( DEFINED TEENSY ) endif() endif() + + +### +# Compiler Command Generation +# + +#| Generate list of compiler commands for clang-tidy usage +set( CMAKE_EXPORT_COMPILE_COMMANDS ON ) + +#| Make sure symlink exists (for convenience) +if ( UNIX ) + # Make sure symlink is created immediately + execute_process ( COMMAND ln -sfn ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_SOURCE_DIR}/. ) + + # Also update before each build + add_custom_command( TARGET ${TARGET_ELF} POST_BUILD + COMMAND ln -sfn ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_SOURCE_DIR}/. + ) +endif () + diff --git a/Lib/clang.c b/Lib/clang.c new file mode 100644 index 0000000..f502409 --- /dev/null +++ b/Lib/clang.c @@ -0,0 +1,61 @@ +/* Copyright (C) 2016 by Jacob Alexander + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +// This file adds various functions that clang doesn't link properly +// AFAIK, clang doesn't have an elegant solution for this, so this is what we gotta do... + +// ----- Includes ----- + +// Compiler Includes +#include + + +void __aeabi_memcpy( void *dest, const void *src, size_t n ) +{ + (void)memcpy(dest, src, n); +} + +void __aeabi_memcpy4( void *dest, const void *src, size_t n ) +{ + memcpy(dest, src, n); +} + +void __aeabi_memclr( void *dest, size_t n ) +{ + memset(dest, 0, n); +} + +void __aeabi_memclr4( void *dest, size_t n ) +{ + memset(dest, 0, n); +} + +void __aeabi_memmove( void *dest, const void *src, size_t n ) +{ + (void)memmove(dest, src, n); +} + +void __aeabi_memset( void *s, size_t n, int c ) +{ + (void)memset(s, c, n); +} + From 3c9a97d51a2f3b94168e46ff1524ceec63703eff Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Mon, 21 Mar 2016 00:43:19 -0700 Subject: [PATCH 21/23] Adding basic mouse button support - Full Mouse support will have to wait for KLL 0.6 * This will include dynamic HID descriptor generation for many wheels and axis depending on the KLL needs - HID descriptor is currently limited to 8 buttons - Technically mouse movement also works (tested by accident), but it's disable for now (needs some API thought) - Adding additional udev rules - Added KRO mode default define --- 98-kiibohd.rules | 6 +++ Output/pjrcUSB/arm/usb_desc.c | 11 ++--- Output/pjrcUSB/arm/usb_mouse.c | 84 ++++++++++++++++++++++++--------- Output/pjrcUSB/arm/usb_mouse.h | 13 ++--- Output/pjrcUSB/capabilities.kll | 15 ++++-- Output/pjrcUSB/output_com.c | 75 +++++++++++++++++++++++++---- Output/pjrcUSB/output_com.h | 3 ++ 7 files changed, 155 insertions(+), 52 deletions(-) diff --git a/98-kiibohd.rules b/98-kiibohd.rules index 955bc13..3dccd01 100644 --- a/98-kiibohd.rules +++ b/98-kiibohd.rules @@ -2,20 +2,26 @@ ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", ENV{ID_MM_DEVICE_IGNORE}="1" ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", ENV{MTP_NO_PROBE}="1" SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", MODE:="0666" + # Kiibohd Serial Interface KERNEL=="ttyACM*", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", SYMLINK+="kiibohd", MODE:="0666", KERNEL=="ttyACM*", ATTRS{idVendor}=="1c11", ATTRS{idProduct}=="b04d", SYMLINK+="kiibohd", MODE:="0666" KERNEL=="ttyACM*", ATTRS{idVendor}=="1c11", ATTRS{idProduct}=="f05c", SYMLINK+="kiibohd", MODE:="0666" + # Kiibohd Device SUBSYSTEMS=="usb", ATTRS{idVendor}=="1c11", ATTRS{idProduct}=="b04d", MODE:="0666" + # DFU Bootloader (MCHCK) ATTRS{idVendor}=="2323", ATTRS{idProduct}=="0001", ENV{ID_MM_DEVICE_IGNORE}="1" ATTRS{idVendor}=="2323", ATTRS{idProduct}=="0001", ENV{MTP_NO_PROBE}="1" SUBSYSTEMS=="usb", ATTRS{idVendor}=="2323", ATTRS{idProduct}=="0001", MODE:="0666" + # Kiibohd DFU Bootloader ATTRS{idVendor}=="1C11", ATTRS{idProduct}=="b007", ENV{ID_MM_DEVICE_IGNORE}="1" ATTRS{idVendor}=="1C11", ATTRS{idProduct}=="b007", ENV{MTP_NO_PROBE}="1" SUBSYSTEMS=="usb", ATTRS{idVendor}=="1c11", ATTRS{idProduct}=="b007", MODE:="0666" + # Kiibohd Force Gauge SUBSYSTEM=="tty", ATTRS{idVendor}=="1c11", ATTRS{idProduct}=="f05c", GROUP="users", MODE="0666", SYMLINK+="force" +SUBSYSTEMS=="usb", ATTRS{idVendor}=="1c11", ATTRS{idProduct}=="f05c", MODE:="0666" diff --git a/Output/pjrcUSB/arm/usb_desc.c b/Output/pjrcUSB/arm/usb_desc.c index 1d9a939..02ffd5d 100644 --- a/Output/pjrcUSB/arm/usb_desc.c +++ b/Output/pjrcUSB/arm/usb_desc.c @@ -314,22 +314,17 @@ static uint8_t mouse_report_desc[] = { 0xa1, 0x02, // Collection (Logical) 0x09, 0x01, // Usage (Pointer) - // Buttons (5 bits) + // Buttons (8 bits) 0xa1, 0x00, // Collection (Physical) - Buttons 0x05, 0x09, // Usage Page (Button) 0x19, 0x01, // Usage Minimum (Button 1) - 0x29, 0x05, // Usage Maximum (Button 5) + 0x29, 0x08, // Usage Maximum (Button 8) 0x15, 0x00, // Logical Minimum (0) 0x25, 0x01, // Logical Maximum (1) 0x75, 0x01, // Report Size (1) - 0x95, 0x05, // Report Count (5) + 0x95, 0x08, // Report Count (8) 0x81, 0x02, // Input (Data,Var,Abs) - // Padding (3 bits) - 0x75, 0x03, // Report Size (3) - 0x95, 0x01, // Report Count (1) - 0x81, 0x03, // Input (Cnst,Var,Abs) - // Pointer (16 bits) 0x05, 0x01, // Usage PAGE (Generic Desktop) 0x09, 0x30, // Usage (X) diff --git a/Output/pjrcUSB/arm/usb_mouse.c b/Output/pjrcUSB/arm/usb_mouse.c index 2b1dc72..43a6f50 100644 --- a/Output/pjrcUSB/arm/usb_mouse.c +++ b/Output/pjrcUSB/arm/usb_mouse.c @@ -1,7 +1,7 @@ /* Teensyduino Core Library * http://www.pjrc.com/teensy/ * Copyright (c) 2013 PJRC.COM, LLC. - * Modified by Jacob Alexander (2015) + * Modified by Jacob Alexander (2015-2016) * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -115,38 +115,78 @@ // ----- Variables ----- -// which buttons are currently pressed -uint8_t usb_mouse_buttons_state=0; +static uint8_t transmit_previous_timeout = 0; -static uint16_t usb_mouse_resolution_x=DEFAULT_XRES; -static uint16_t usb_mouse_resolution_y=DEFAULT_YRES; -static uint16_t usb_mouse_position_x=DEFAULT_XRES/2; -static uint16_t usb_mouse_position_y=DEFAULT_YRES/2; -static uint32_t usb_mouse_scale_x=DEFAULT_XSCALE; -static uint32_t usb_mouse_scale_y=DEFAULT_YSCALE; -static uint32_t usb_mouse_offset_x=DEFAULT_XSCALE/2-1; -static uint32_t usb_mouse_offset_y=DEFAULT_YSCALE/2-1; +// which buttons are currently pressed +uint8_t usb_mouse_buttons_state = 0; + +static uint16_t usb_mouse_resolution_x = DEFAULT_XRES; +static uint16_t usb_mouse_resolution_y = DEFAULT_YRES; +static uint16_t usb_mouse_position_x = DEFAULT_XRES / 2; +static uint16_t usb_mouse_position_y = DEFAULT_YRES / 2; +static uint32_t usb_mouse_scale_x = DEFAULT_XSCALE; +static uint32_t usb_mouse_scale_y = DEFAULT_YSCALE; +static uint32_t usb_mouse_offset_x = DEFAULT_XSCALE / 2 - 1; +static uint32_t usb_mouse_offset_y = DEFAULT_YSCALE / 2 - 1; // ----- Functions ----- -// Set the mouse buttons. To create a "click", 2 calls are needed, -// one to push the button down and the second to release it -int usb_mouse_buttons(uint8_t left, uint8_t middle, uint8_t right) +// Process pending mouse commands +// XXX Missing mouse movement and wheels +// Proper support will require KLL generation of the USB descriptors +// Similar support will be required for joystick control +void usb_mouse_send() { - uint8_t mask=0; + uint32_t wait_count = 0; + usb_packet_t *tx_packet; - if (left) mask |= 1; - if (middle) mask |= 4; - if (right) mask |= 2; - usb_mouse_buttons_state = mask; - return usb_mouse_move(0, 0, 0); + // Wait till ready + while ( 1 ) + { + if ( !usb_configuration ) + { + erro_print("USB not configured..."); + return; + } + + // Attempt to acquire a USB packet for the mouse endpoint + if ( usb_tx_packet_count( MOUSE_ENDPOINT ) < TX_PACKET_LIMIT ) + { + tx_packet = usb_malloc(); + if ( tx_packet ) + break; + } + + if ( ++wait_count > TX_TIMEOUT || transmit_previous_timeout ) + { + transmit_previous_timeout = 1; + warn_print("USB Transmit Timeout..."); + return; + } + yield(); + } + + transmit_previous_timeout = 0; + + // Prepare USB Mouse Packet + // TODO Document each byte + // TODO Dynamically generate this code based on KLL requirements + *(tx_packet->buf + 0) = USBMouse_Buttons; + *(tx_packet->buf + 1) = 0; + *(tx_packet->buf + 2) = 0; + *(tx_packet->buf + 3) = 0; + *(tx_packet->buf + 4) = 0; + tx_packet->len = 5; + usb_tx( MOUSE_ENDPOINT, tx_packet ); + + // Clear status and state + USBMouse_Buttons = 0; + USBMouse_Changed = 0; } -static uint8_t transmit_previous_timeout=0; - // Move the mouse. x, y and wheel are -127 to 127. Use 0 for no movement. int usb_mouse_move(int8_t x, int8_t y, int8_t wheel) { diff --git a/Output/pjrcUSB/arm/usb_mouse.h b/Output/pjrcUSB/arm/usb_mouse.h index ffa9fe2..397d967 100644 --- a/Output/pjrcUSB/arm/usb_mouse.h +++ b/Output/pjrcUSB/arm/usb_mouse.h @@ -1,7 +1,7 @@ /* Teensyduino Core Library * http://www.pjrc.com/teensy/ * Copyright (c) 2013 PJRC.COM, LLC. - * Modified by Jacob Alexander (2015) + * Modified by Jacob Alexander (2015-2016) * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -43,16 +43,11 @@ // ----- Functions ----- +// Proces pending mouse commands +void usb_mouse_send(); + // TODO - More generic -int usb_mouse_buttons( uint8_t left, uint8_t middle, uint8_t right ); int usb_mouse_move( int8_t x, int8_t y, int8_t wheel ); int usb_mouse_position( uint16_t x, uint16_t y ); void usb_mouse_screen_size( uint16_t width, uint16_t height, uint8_t mac ); -extern uint8_t usb_mouse_buttons_state; - -// TODO - Move -#define MOUSE_LEFT 1 -#define MOUSE_MIDDLE 4 -#define MOUSE_RIGHT 2 -#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE) diff --git a/Output/pjrcUSB/capabilities.kll b/Output/pjrcUSB/capabilities.kll index 7646625..960c246 100644 --- a/Output/pjrcUSB/capabilities.kll +++ b/Output/pjrcUSB/capabilities.kll @@ -1,10 +1,10 @@ Name = pjrcUSBCapabilities; -Version = 0.6; -Author = "HaaTa (Jacob Alexander) 2014-2015"; -KLL = 0.3c; +Version = 0.7; +Author = "HaaTa (Jacob Alexander) 2014-2016"; +KLL = 0.3d; # Modified Date -Date = 2015-08-21; +Date = 2016-03-20; # Output capabilities @@ -12,6 +12,7 @@ consCtrlOut => Output_consCtrlSend_capability( consCode : 2 ); noneOut => Output_noneSend_capability(); sysCtrlOut => Output_sysCtrlSend_capability( sysCode : 1 ); usbKeyOut => Output_usbCodeSend_capability( usbCode : 1 ); +mouseOut => Output_usbMouse_capability( mouseCode : 2 ); # Configuration capabilities kbdProtocolBoot => Output_kbdProtocolBoot_capability(); @@ -21,6 +22,12 @@ kbdProtocolNKRO => Output_kbdProtocolNKRO_capability(); keyboardLocale => KeyboardLocale_define; keyboardLocale = 0; +# Default KRO Mode +# Set to 0 for Boot Mode (6KRO) +# Set to 1 for NKRO Mode (default) +usbProtocol => USBProtocol_define; +usbProtocol = 1; + # Bootloader Mode capability # XXX # By default this is disabled on purpose diff --git a/Output/pjrcUSB/output_com.c b/Output/pjrcUSB/output_com.c index b18bbdb..37389cb 100644 --- a/Output/pjrcUSB/output_com.c +++ b/Output/pjrcUSB/output_com.c @@ -37,8 +37,12 @@ #include "arm/usb_dev.h" #include "arm/usb_keyboard.h" #include "arm/usb_serial.h" +#include "arm/usb_mouse.h" #endif +// KLL +#include + // Local Includes #include "output_com.h" @@ -47,14 +51,15 @@ // ----- Macros ----- // Used to build a bitmap lookup table from a byte addressable array -#define byteLookup( byte ) case (( byte ) * ( 8 )): bytePosition = byte; byteShift = 0; break; \ - case (( byte ) * ( 8 ) + ( 1 )): bytePosition = byte; byteShift = 1; break; \ - case (( byte ) * ( 8 ) + ( 2 )): bytePosition = byte; byteShift = 2; break; \ - case (( byte ) * ( 8 ) + ( 3 )): bytePosition = byte; byteShift = 3; break; \ - case (( byte ) * ( 8 ) + ( 4 )): bytePosition = byte; byteShift = 4; break; \ - case (( byte ) * ( 8 ) + ( 5 )): bytePosition = byte; byteShift = 5; break; \ - case (( byte ) * ( 8 ) + ( 6 )): bytePosition = byte; byteShift = 6; break; \ - case (( byte ) * ( 8 ) + ( 7 )): bytePosition = byte; byteShift = 7; break +#define byteLookup( byte ) \ + case (( byte ) * ( 8 )): bytePosition = byte; byteShift = 0; break; \ + case (( byte ) * ( 8 ) + ( 1 )): bytePosition = byte; byteShift = 1; break; \ + case (( byte ) * ( 8 ) + ( 2 )): bytePosition = byte; byteShift = 2; break; \ + case (( byte ) * ( 8 ) + ( 3 )): bytePosition = byte; byteShift = 3; break; \ + case (( byte ) * ( 8 ) + ( 4 )): bytePosition = byte; byteShift = 4; break; \ + case (( byte ) * ( 8 ) + ( 5 )): bytePosition = byte; byteShift = 5; break; \ + case (( byte ) * ( 8 ) + ( 6 )): bytePosition = byte; byteShift = 6; break; \ + case (( byte ) * ( 8 ) + ( 7 )): bytePosition = byte; byteShift = 7; break @@ -111,15 +116,21 @@ uint8_t USBKeys_SentCLI = 0; // 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana volatile uint8_t USBKeys_LEDs = 0; +// Currently pressed mouse buttons, bitmask, 0 represents no buttons pressed +volatile uint16_t USBMouse_Buttons = 0; + // Protocol setting from the host. // 0 - Boot Mode // 1 - NKRO Mode (Default, unless set by a BIOS or boot interface) -volatile uint8_t USBKeys_Protocol = 1; +volatile uint8_t USBKeys_Protocol = USBProtocol_define; // Indicate if USB should send update // OS only needs update if there has been a change in state USBKeyChangeState USBKeys_Changed = USBKeyChangeState_None; +// Indicate if USB should send update +uint8_t USBMouse_Changed = 0; + // the idle configuration, how often we send the report to the // host (ms * 4) even when it hasn't changed uint8_t USBKeys_Idle_Config = 125; @@ -505,6 +516,48 @@ void Output_flashMode_capability( uint8_t state, uint8_t stateType, uint8_t *arg Output_firmwareReload(); } +// Sends a mouse command over the USB Output buffer +// XXX This function *will* be changing in the future +// If you use it, be prepared that your .kll files will break in the future (post KLL 0.5) +// Argument #1: USB Mouse Button # +void Output_usbMouse_capability( uint8_t state, uint8_t stateType, uint8_t *args ) +{ + // Display capability name + if ( stateType == 0xFF && state == 0xFF ) + { + print("Output_usbMouse(mouseButton)"); + return; + } + + // Determine which mouse button was sent + // The USB spec defines up to a max of 0xFFFF buttons + // The usual are: + // 1 - Button 1 - (Primary) + // 2 - Button 2 - (Secondary) + // 3 - Button 3 - (Tertiary) + uint16_t mouse_button = *(uint16_t*)(&args[0]); + + // If set to zero, ignore + if ( mouse_button == 0 ) + return; + + // Adjust for bit shift + mouse_button -= 1; + + // Only send mouse button if in press or hold state + if ( stateType == 0x00 && state == 0x03 ) // Release state + { + USBMouse_Buttons &= ~(1 << mouse_button); + } + else + { + USBMouse_Buttons |= (1 << mouse_button); + } + + // TODO Add more states when adding full support + USBMouse_Changed = 1; +} + // ----- Functions ----- @@ -552,6 +605,10 @@ inline void Output_send() for ( uint8_t c = USBKeys_Sent; c < USB_BOOT_MAX_KEYS; c++ ) USBKeys_Keys[c] = 0; + // Process mouse actions + while ( USBMouse_Changed ) + usb_mouse_send(); + // Send keypresses while there are pending changes while ( USBKeys_Changed ) usb_keyboard_send(); diff --git a/Output/pjrcUSB/output_com.h b/Output/pjrcUSB/output_com.h index 2448683..abb8124 100644 --- a/Output/pjrcUSB/output_com.h +++ b/Output/pjrcUSB/output_com.h @@ -72,11 +72,14 @@ extern uint16_t USBKeys_ConsCtrl; // 1KRO container for Consumer Contro extern volatile uint8_t USBKeys_Protocol; // 0 - Boot Mode, 1 - NKRO Mode +extern volatile uint16_t USBMouse_Buttons; // Bitmask for mouse buttons + // Misc variables (XXX Some are only properly utilized using AVR) extern uint8_t USBKeys_Idle_Config; extern uint8_t USBKeys_Idle_Count; extern USBKeyChangeState USBKeys_Changed; +extern uint8_t USBMouse_Changed; extern volatile uint8_t Output_Available; // 0 - Output module not fully functional, 1 - Output module working From 18aef02a1feaf1e3f49085cc82e36221039530b4 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Mon, 21 Mar 2016 22:23:57 -0700 Subject: [PATCH 22/23] Adding relative movement mouse key support - Still very basic (lots of room for improvement) - Capability format will likely change at some point - 16 bit movement control, however repeat rate limits usability (will need KLL 0.4 to make better) --- Output/pjrcUSB/arm/usb_desc.c | 22 ++++++++++-------- Output/pjrcUSB/arm/usb_mouse.c | 14 +++++------ Output/pjrcUSB/capabilities.kll | 6 ++--- Output/pjrcUSB/output_com.c | 41 ++++++++++++++++++++++++--------- Output/pjrcUSB/output_com.h | 14 +++++++++-- 5 files changed, 64 insertions(+), 33 deletions(-) diff --git a/Output/pjrcUSB/arm/usb_desc.c b/Output/pjrcUSB/arm/usb_desc.c index 02ffd5d..b0be2a0 100644 --- a/Output/pjrcUSB/arm/usb_desc.c +++ b/Output/pjrcUSB/arm/usb_desc.c @@ -309,32 +309,33 @@ static uint8_t sys_ctrl_report_desc[] = { static uint8_t mouse_report_desc[] = { 0x05, 0x01, // Usage Page (Generic Desktop) 0x09, 0x02, // Usage (Mouse) - 0xa1, 0x01, // Collection (Application) + 0xA1, 0x01, // Collection (Application) 0x09, 0x02, // Usage (Mouse) - 0xa1, 0x02, // Collection (Logical) + 0xA1, 0x02, // Collection (Logical) 0x09, 0x01, // Usage (Pointer) - // Buttons (8 bits) - 0xa1, 0x00, // Collection (Physical) - Buttons + // Buttons (16 bits) + 0xA1, 0x00, // Collection (Physical) - Buttons 0x05, 0x09, // Usage Page (Button) 0x19, 0x01, // Usage Minimum (Button 1) - 0x29, 0x08, // Usage Maximum (Button 8) + 0x29, 0x10, // Usage Maximum (Button 16) 0x15, 0x00, // Logical Minimum (0) 0x25, 0x01, // Logical Maximum (1) 0x75, 0x01, // Report Size (1) - 0x95, 0x08, // Report Count (8) + 0x95, 0x10, // Report Count (16) 0x81, 0x02, // Input (Data,Var,Abs) - // Pointer (16 bits) + // Pointer (32 bits) 0x05, 0x01, // Usage PAGE (Generic Desktop) 0x09, 0x30, // Usage (X) 0x09, 0x31, // Usage (Y) - 0x15, 0x81, // Logical Minimum (-127) - 0x25, 0x7f, // Logical Maximum (127) - 0x75, 0x08, // Report Size (8) + 0x16, 0x01, 0x80, // Logical Minimum (-32 767) + 0x26, 0xFF, 0x7F, // Logical Maximum (32 767) + 0x75, 0x10, // Report Size (16) 0x95, 0x02, // Report Count (2) 0x81, 0x06, // Input (Data,Var,Rel) + /* // Vertical Wheel // - Multiplier (2 bits) 0xa1, 0x02, // Collection (Logical) @@ -377,6 +378,7 @@ static uint8_t mouse_report_desc[] = { 0x81, 0x06, // Input (Data,Var,Rel) 0xc0, // End Collection - Horizontal Wheel + */ 0xc0, // End Collection - Buttons 0xc0, // End Collection - Mouse Logical 0xc0 // End Collection - Mouse Application diff --git a/Output/pjrcUSB/arm/usb_mouse.c b/Output/pjrcUSB/arm/usb_mouse.c index 43a6f50..5de7712 100644 --- a/Output/pjrcUSB/arm/usb_mouse.c +++ b/Output/pjrcUSB/arm/usb_mouse.c @@ -171,18 +171,18 @@ void usb_mouse_send() transmit_previous_timeout = 0; // Prepare USB Mouse Packet - // TODO Document each byte // TODO Dynamically generate this code based on KLL requirements - *(tx_packet->buf + 0) = USBMouse_Buttons; - *(tx_packet->buf + 1) = 0; - *(tx_packet->buf + 2) = 0; - *(tx_packet->buf + 3) = 0; - *(tx_packet->buf + 4) = 0; - tx_packet->len = 5; + uint16_t *packet_data = (uint16_t*)(&tx_packet->buf[0]); + packet_data[0] = USBMouse_Buttons; + packet_data[1] = USBMouse_Relative_x; + packet_data[2] = USBMouse_Relative_y; + tx_packet->len = 6; usb_tx( MOUSE_ENDPOINT, tx_packet ); // Clear status and state USBMouse_Buttons = 0; + USBMouse_Relative_x = 0; + USBMouse_Relative_y = 0; USBMouse_Changed = 0; } diff --git a/Output/pjrcUSB/capabilities.kll b/Output/pjrcUSB/capabilities.kll index 960c246..c83f910 100644 --- a/Output/pjrcUSB/capabilities.kll +++ b/Output/pjrcUSB/capabilities.kll @@ -1,10 +1,10 @@ Name = pjrcUSBCapabilities; -Version = 0.7; +Version = 0.8; Author = "HaaTa (Jacob Alexander) 2014-2016"; KLL = 0.3d; # Modified Date -Date = 2016-03-20; +Date = 2016-03-21; # Output capabilities @@ -12,7 +12,7 @@ consCtrlOut => Output_consCtrlSend_capability( consCode : 2 ); noneOut => Output_noneSend_capability(); sysCtrlOut => Output_sysCtrlSend_capability( sysCode : 1 ); usbKeyOut => Output_usbCodeSend_capability( usbCode : 1 ); -mouseOut => Output_usbMouse_capability( mouseCode : 2 ); +mouseOut => Output_usbMouse_capability( mouseCode : 2, relative_x : 2, relative_y : 2 ); # Configuration capabilities kbdProtocolBoot => Output_kbdProtocolBoot_capability(); diff --git a/Output/pjrcUSB/output_com.c b/Output/pjrcUSB/output_com.c index 37389cb..39ee0b0 100644 --- a/Output/pjrcUSB/output_com.c +++ b/Output/pjrcUSB/output_com.c @@ -119,6 +119,10 @@ volatile uint8_t USBKeys_LEDs = 0; // Currently pressed mouse buttons, bitmask, 0 represents no buttons pressed volatile uint16_t USBMouse_Buttons = 0; +// Relative mouse axis movement, stores pending movement +volatile uint16_t USBMouse_Relative_x = 0; +volatile uint16_t USBMouse_Relative_y = 0; + // Protocol setting from the host. // 0 - Boot Mode // 1 - NKRO Mode (Default, unless set by a BIOS or boot interface) @@ -129,7 +133,7 @@ volatile uint8_t USBKeys_Protocol = USBProtocol_define; USBKeyChangeState USBKeys_Changed = USBKeyChangeState_None; // Indicate if USB should send update -uint8_t USBMouse_Changed = 0; +USBMouseChangeState USBMouse_Changed = 0; // the idle configuration, how often we send the report to the // host (ms * 4) even when it hasn't changed @@ -519,13 +523,15 @@ void Output_flashMode_capability( uint8_t state, uint8_t stateType, uint8_t *arg // Sends a mouse command over the USB Output buffer // XXX This function *will* be changing in the future // If you use it, be prepared that your .kll files will break in the future (post KLL 0.5) -// Argument #1: USB Mouse Button # +// Argument #1: USB Mouse Button (16 bit) +// Argument #2: USB X Axis (16 bit) relative +// Argument #3: USB Y Axis (16 bit) relative void Output_usbMouse_capability( uint8_t state, uint8_t stateType, uint8_t *args ) { // Display capability name if ( stateType == 0xFF && state == 0xFF ) { - print("Output_usbMouse(mouseButton)"); + print("Output_usbMouse(mouseButton,relX,relY)"); return; } @@ -537,25 +543,38 @@ void Output_usbMouse_capability( uint8_t state, uint8_t stateType, uint8_t *args // 3 - Button 3 - (Tertiary) uint16_t mouse_button = *(uint16_t*)(&args[0]); - // If set to zero, ignore - if ( mouse_button == 0 ) - return; + // X/Y Relative Axis + uint16_t mouse_x = *(uint16_t*)(&args[2]); + uint16_t mouse_y = *(uint16_t*)(&args[4]); // Adjust for bit shift - mouse_button -= 1; + uint16_t mouse_button_shift = mouse_button - 1; // Only send mouse button if in press or hold state if ( stateType == 0x00 && state == 0x03 ) // Release state { - USBMouse_Buttons &= ~(1 << mouse_button); + // Release + if ( mouse_button ) + USBMouse_Buttons &= ~(1 << mouse_button_shift); } else { - USBMouse_Buttons |= (1 << mouse_button); + // Press or hold + if ( mouse_button ) + USBMouse_Buttons |= (1 << mouse_button_shift); + + if ( mouse_x ) + USBMouse_Relative_x = mouse_x; + if ( mouse_y ) + USBMouse_Relative_y = mouse_y; } - // TODO Add more states when adding full support - USBMouse_Changed = 1; + // Trigger updates + if ( mouse_button ) + USBMouse_Changed |= USBMouseChangeState_Buttons; + + if ( mouse_x || mouse_y ) + USBMouse_Changed |= USBMouseChangeState_Relative; } diff --git a/Output/pjrcUSB/output_com.h b/Output/pjrcUSB/output_com.h index abb8124..36369eb 100644 --- a/Output/pjrcUSB/output_com.h +++ b/Output/pjrcUSB/output_com.h @@ -56,6 +56,14 @@ typedef enum USBKeyChangeState { USBKeyChangeState_All = 0x7F, } USBKeyChangeState; +// Allows for selective USB descriptor pushes +// However, in most cases everything is updated for each packet push +typedef enum USBMouseChangeState { + USBMouseChangeState_None = 0x00, + USBMouseChangeState_Buttons = 0x01, + USBMouseChangeState_Relative = 0x02, +} USBMouseChangeState; + // ----- Variables ----- @@ -73,13 +81,15 @@ extern uint16_t USBKeys_ConsCtrl; // 1KRO container for Consumer Contro extern volatile uint8_t USBKeys_Protocol; // 0 - Boot Mode, 1 - NKRO Mode extern volatile uint16_t USBMouse_Buttons; // Bitmask for mouse buttons +extern volatile uint16_t USBMouse_Relative_x; +extern volatile uint16_t USBMouse_Relative_y; // Misc variables (XXX Some are only properly utilized using AVR) extern uint8_t USBKeys_Idle_Config; extern uint8_t USBKeys_Idle_Count; -extern USBKeyChangeState USBKeys_Changed; -extern uint8_t USBMouse_Changed; +extern USBKeyChangeState USBKeys_Changed; +extern USBMouseChangeState USBMouse_Changed; extern volatile uint8_t Output_Available; // 0 - Output module not fully functional, 1 - Output module working From bfaed8f58ce8aaa307dee2c4500fee426170b8ed Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Tue, 22 Mar 2016 19:51:43 -0700 Subject: [PATCH 23/23] Move matrix information to a cli command --- Scan/MatrixARM/matrix_scan.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/Scan/MatrixARM/matrix_scan.c b/Scan/MatrixARM/matrix_scan.c index bbce1df..7d8897b 100644 --- a/Scan/MatrixARM/matrix_scan.c +++ b/Scan/MatrixARM/matrix_scan.c @@ -52,6 +52,7 @@ nat_ptr_t Matrix_divCounter = 0; // CLI Functions void cliFunc_matrixDebug( char* args ); +void cliFunc_matrixInfo( char* args ); void cliFunc_matrixState( char* args ); @@ -60,10 +61,12 @@ void cliFunc_matrixState( char* args ); // Scan Module command dictionary CLIDict_Entry( matrixDebug, "Enables matrix debug mode, prints out each scan code." NL "\t\tIf argument \033[35mT\033[0m is given, prints out each scan code state transition." ); +CLIDict_Entry( matrixInfo, "Print info about the configured matrix." ); CLIDict_Entry( matrixState, "Prints out the current scan table N times." NL "\t\t \033[1mO\033[0m - Off, \033[1;33mP\033[0m - Press, \033[1;32mH\033[0m - Hold, \033[1;35mR\033[0m - Release, \033[1;31mI\033[0m - Invalid" ); CLIDict_Def( matrixCLIDict, "Matrix Module Commands" ) = { CLIDict_Item( matrixDebug ), + CLIDict_Item( matrixInfo ), CLIDict_Item( matrixState ), { 0, 0, 0 } // Null entry for dictionary end }; @@ -204,30 +207,18 @@ void Matrix_setup() // Register Matrix CLI dictionary CLI_registerDictionary( matrixCLIDict, matrixCLIDictName ); - info_msg("Columns: "); - printHex( Matrix_colsNum ); - // Setup Strobe Pins for ( uint8_t pin = 0; pin < Matrix_colsNum; pin++ ) { Matrix_pin( Matrix_cols[ pin ], Type_StrobeSetup ); } - print( NL ); - info_msg("Rows: "); - printHex( Matrix_rowsNum ); - // Setup Sense Pins for ( uint8_t pin = 0; pin < Matrix_rowsNum; pin++ ) { Matrix_pin( Matrix_rows[ pin ], Type_SenseSetup ); } - print( NL ); - info_msg("Max Keys: "); - printHex( Matrix_maxKeys ); - print( NL ); - // Clear out Debounce Array for ( uint8_t item = 0; item < Matrix_maxKeys; item++ ) { @@ -598,7 +589,22 @@ void Matrix_currentChange( unsigned int current ) // ----- CLI Command Functions ----- -void cliFunc_matrixDebug ( char* args ) +void cliFunc_matrixInfo( char* args ) +{ + print( NL ); + info_msg("Columns: "); + printHex( Matrix_colsNum ); + + print( NL ); + info_msg("Rows: "); + printHex( Matrix_rowsNum ); + + print( NL ); + info_msg("Max Keys: "); + printHex( Matrix_maxKeys ); +} + +void cliFunc_matrixDebug( char* args ) { // Parse number from argument // NOTE: Only first argument is used @@ -632,7 +638,7 @@ void cliFunc_matrixDebug ( char* args ) printInt8( matrixDebugMode ); } -void cliFunc_matrixState ( char* args ) +void cliFunc_matrixState( char* args ) { // Parse number from argument // NOTE: Only first argument is used