From 39dbb85c1a64681eafc03592f26c0d53f97406bb Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Mon, 11 Apr 2016 18:58:06 -0700 Subject: [PATCH] Initial structure of ARM cap sense controller --- Scan/CapSense/capabilities.kll | 11 +++ Scan/CapSense/matrix_scan.c | 126 +++++++++++++++++++++++++++++++++ Scan/CapSense/matrix_scan.h | 38 ++++++++++ Scan/CapSense/matrix_setup.h | 20 ++++++ Scan/CapSense/setup.cmake | 30 ++++++++ Scan/CapTest1/defaultMap.kll | 73 +++++++++++++++++++ Scan/CapTest1/matrix.h | 32 +++++++++ Scan/CapTest1/scan_loop.c | 92 ++++++++++++++++++++++++ Scan/CapTest1/scan_loop.h | 40 +++++++++++ Scan/CapTest1/setup.cmake | 32 +++++++++ 10 files changed, 494 insertions(+) create mode 100644 Scan/CapSense/capabilities.kll create mode 100644 Scan/CapSense/matrix_scan.c create mode 100644 Scan/CapSense/matrix_scan.h create mode 100644 Scan/CapSense/matrix_setup.h create mode 100644 Scan/CapSense/setup.cmake create mode 100644 Scan/CapTest1/defaultMap.kll create mode 100644 Scan/CapTest1/matrix.h create mode 100644 Scan/CapTest1/scan_loop.c create mode 100644 Scan/CapTest1/scan_loop.h create mode 100644 Scan/CapTest1/setup.cmake diff --git a/Scan/CapSense/capabilities.kll b/Scan/CapSense/capabilities.kll new file mode 100644 index 0000000..0de41cf --- /dev/null +++ b/Scan/CapSense/capabilities.kll @@ -0,0 +1,11 @@ +Name = CapSenseCapabilities; +Version = 0.1; +Author = "HaaTa (Jacob Alexander) 2016"; +KLL = 0.3d; + +# Modified Date +Date = 2016-04-11; + +# Defines available to the CapSense sub-module +# TODO Add cap sense configuration here + diff --git a/Scan/CapSense/matrix_scan.c b/Scan/CapSense/matrix_scan.c new file mode 100644 index 0000000..2808ec1 --- /dev/null +++ b/Scan/CapSense/matrix_scan.c @@ -0,0 +1,126 @@ +/* Copyright (C) 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this file. If not, see . + */ + +// ----- Includes ----- + +// Compiler Includes +#include + +// Project Includes +#include +#include +#include +#include +#include +#include + +// Local Includes +#include "matrix_scan.h" + +// Matrix Configuration +//#include + + + +// ----- Defines ----- + +// ----- Function Declarations ----- + +// CLI Functions +void cliFunc_matrixDebug( char* args ); +void cliFunc_matrixInfo( char* args ); +void cliFunc_matrixState( char* args ); + + + +// ----- Variables ----- + +// 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 +}; + + + +// ----- Functions ----- + +void Matrix_setup() +{ + // Register Matrix CLI dictionary + CLI_registerDictionary( matrixCLIDict, matrixCLIDictName ); +} + +// Scan the matrix for keypresses +// NOTE: scanNum should be reset to 0 after a USB send (to reset all the counters) +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_matrixInfo( char* args ) +{ +} + +void cliFunc_matrixDebug( char* args ) +{ + // Parse number from argument + // NOTE: Only first argument is used + char* arg1Ptr; + char* arg2Ptr; + CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); + + // Set the matrix debug flag depending on the argument + // If no argument, set to scan code only + // If set to T, set to state transition + switch ( arg1Ptr[0] ) + { + // T as argument + case 'T': + case 't': + break; + + // No argument + case '\0': + break; + + // Invalid argument + default: + return; + } +} + +void cliFunc_matrixState( char* args ) +{ +} + diff --git a/Scan/CapSense/matrix_scan.h b/Scan/CapSense/matrix_scan.h new file mode 100644 index 0000000..3c7efb9 --- /dev/null +++ b/Scan/CapSense/matrix_scan.h @@ -0,0 +1,38 @@ +/* Copyright (C) 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this file. If not, see . + */ + +#pragma once + +// ----- Includes ----- + +// KLL Generated Defines +#include + + + +// ----- Defines ----- + +// ----- Enums ----- + +// ----- Structs ----- + +// ----- Functions ----- + +void Matrix_setup(); +void Matrix_scan( uint16_t scanNum ); + +void Matrix_currentChange( unsigned int current ); + diff --git a/Scan/CapSense/matrix_setup.h b/Scan/CapSense/matrix_setup.h new file mode 100644 index 0000000..20b6068 --- /dev/null +++ b/Scan/CapSense/matrix_setup.h @@ -0,0 +1,20 @@ +/* Copyright (C) 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this file. If not, see . + */ + +#pragma once + +// TODO + diff --git a/Scan/CapSense/setup.cmake b/Scan/CapSense/setup.cmake new file mode 100644 index 0000000..f56516a --- /dev/null +++ b/Scan/CapSense/setup.cmake @@ -0,0 +1,30 @@ +###| CMake Kiibohd Controller Scan Module |### +# +# Written by Jacob Alexander in 2016 for the Kiibohd Controller +# +# Released into the Public Domain +# +### + + +### +# Sub-module flag, cannot be included stand-alone +# +set ( SubModule 1 ) + + +### +# Module C files +# +set ( Module_SRCS + matrix_scan.c +) + + +### +# Compiler Family Compatibility +# +set ( ModuleCompatibility + arm +) + diff --git a/Scan/CapTest1/defaultMap.kll b/Scan/CapTest1/defaultMap.kll new file mode 100644 index 0000000..5fa6ce6 --- /dev/null +++ b/Scan/CapTest1/defaultMap.kll @@ -0,0 +1,73 @@ +Name = CapTest1; +Version = 0.3d; +Author = "HaaTa (Jacob Alexander) 2016"; +KLL = 0.3c; + +# Modified Date +Date = 2016-04-11; + +# TODO +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 + diff --git a/Scan/CapTest1/matrix.h b/Scan/CapTest1/matrix.h new file mode 100644 index 0000000..eb92a4b --- /dev/null +++ b/Scan/CapTest1/matrix.h @@ -0,0 +1,32 @@ +/* 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this file. If not, see . + */ + +#pragma once + +// ----- Includes ----- + +// Project Includes +#include + + + +// ----- Matrix Definition ----- + +// TODO +// Define possible strobes +// Define possible senses +// Misc pins required for control + diff --git a/Scan/CapTest1/scan_loop.c b/Scan/CapTest1/scan_loop.c new file mode 100644 index 0000000..d045644 --- /dev/null +++ b/Scan/CapTest1/scan_loop.c @@ -0,0 +1,92 @@ +/* Copyright (C) 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this file. If not, see . + */ + +// ----- Includes ----- + +// Compiler Includes +#include + +// Project Includes +#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 cap sense matrix pins for 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; +} + + +// 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 ); +} + + + +// ----- Capabilities ----- + diff --git a/Scan/CapTest1/scan_loop.h b/Scan/CapTest1/scan_loop.h new file mode 100644 index 0000000..1824849 --- /dev/null +++ b/Scan/CapTest1/scan_loop.h @@ -0,0 +1,40 @@ +/* Copyright (C) 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this file. If not, see . + */ + +#pragma once + +// ----- Includes ----- + +// Compiler Includes +#include + + + +// ----- Functions ----- + +// Functions to be called by main.c +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 + + +// ----- Capabilities ----- + diff --git a/Scan/CapTest1/setup.cmake b/Scan/CapTest1/setup.cmake new file mode 100644 index 0000000..49e0ea0 --- /dev/null +++ b/Scan/CapTest1/setup.cmake @@ -0,0 +1,32 @@ +###| CMake Kiibohd Controller Scan Module |### +# +# Written by Jacob Alexander in 2016 for the Kiibohd Controller +# +# Released into the Public Domain +# +### + + +### +# Required Submodules +# + +AddModule ( Scan CapSense ) + + +### +# Module C files +# + +set ( Module_SRCS + scan_loop.c +) + + +### +# Compiler Family Compatibility +# +set ( ModuleCompatibility + arm +) +