]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
Adding configurable DebounceDivThreshold
authorJacob Alexander <haata@kiibohd.com>
Sun, 1 Mar 2015 06:13:17 +0000 (22:13 -0800)
committerJacob Alexander <haata@kiibohd.com>
Sun, 1 Mar 2015 06:13:17 +0000 (22:13 -0800)
Can be specified from any .kll file

DebounceDivThreshold = 0xFFFFFFFF
Sets to max debounce, default is 0xFFFF.
The 0xFFFFFFFF is about a 2x longer debounce
The max requires more ram (as it uses 32 bit variables instead of 16).

Added support for submodule capabilities files.

Lib/CMake/kll.cmake
Lib/CMake/modules.cmake
Scan/MatrixARM/capabilities.kll [new file with mode: 0644]
Scan/MatrixARM/matrix_scan.c
Scan/MatrixARM/matrix_scan.h

index 09ec0d122836b269ff19958ba6646bd5142eb6c8..5d007d2e3d9c0029e20b1324800a47b37e638488 100644 (file)
@@ -1,6 +1,6 @@
 ###| CMAKE Kiibohd Controller KLL Configurator |###
 #
-# Written by Jacob Alexander in 2014 for the Kiibohd Controller
+# Written by Jacob Alexander in 2014-2015 for the Kiibohd Controller
 #
 # Released into the Public Domain
 #
@@ -46,14 +46,10 @@ endif () # kll/kll.py exists
 
 #| KLL_DEPENDS is used to build a dependency tree for kll.py, this way when files are changed, kll.py gets re-run
 
-#| Search for capabilities.kll in each module directory
-foreach ( DIR ${ScanModulePath} ${MacroModulePath} ${OutputModulePath} ${DebugModulePath} )
-       # capabilities.kll exists, add to BaseMap
-       set ( filename "${PROJECT_SOURCE_DIR}/${DIR}/capabilities.kll" )
-       if ( EXISTS ${filename} )
-               set ( BaseMap_Args ${BaseMap_Args} ${filename} )
-               set ( KLL_DEPENDS ${KLL_DEPENDS} ${filename} )
-       endif ()
+#| Add each of the detected capabilities.kll
+foreach ( filename ${ScanModule_KLL} ${MacroModule_KLL} ${OutputModule_KLL} ${DebugModule_KLL} )
+       set ( BaseMap_Args ${BaseMap_Args} ${filename} )
+       set ( KLL_DEPENDS ${KLL_DEPENDS} ${filename} )
 endforeach ()
 
 #| If set BaseMap cannot be found, use default map
index 02ecbe8e4c69c59ca7a4aad5e2ce3393cc44be77..e251aa14b000baaf5d4415e6bdaefe57fad4e43d 100644 (file)
@@ -1,6 +1,6 @@
 ###| CMAKE Kiibohd Controller Source Configurator |###
 #
-# Written by Jacob Alexander in 2011-2014 for the Kiibohd Controller
+# Written by Jacob Alexander in 2011-2015 for the Kiibohd Controller
 #
 # Released into the Public Domain
 #
@@ -104,10 +104,8 @@ function ( AddModule ModuleType ModuleName )
        PathPrepend ( Module_SRCS ${ModulePath} ${Module_SRCS} )
 
        # Check the current scope to see if a sub-module added some source files
-       set ( Module_SRCS ${${ModuleType}_SRCS} ${Module_SRCS} )
-
        # Append each of the sources to each type of module srcs list
-       set ( ${ModuleType}_SRCS ${Module_SRCS} )
+       set ( ${ModuleType}_SRCS ${${ModuleType}_SRCS} ${Module_SRCS} )
 
        # Add .h files
        add_definitions ( -I${ModuleFullPath} )
@@ -124,8 +122,17 @@ function ( AddModule ModuleType ModuleName )
                endif ()
        endforeach ()
 
-       # Finally, add the sources to the parent scope (i.e. return)
+       # Check for any capabilities.kll files in the Module
+       set ( kll_capabilities_file "${ModuleFullPath}/capabilities.kll" )
+       if ( EXISTS ${kll_capabilities_file} )
+               # Add the kll file and any submodule kll files to the running list
+               set ( ${ModuleType}Module_KLL ${${ModuleType}Module_KLL} ${kll_capabilities_file} )
+       endif ()
+
+
+       # Finally, add the sources and kll files to the parent scope (i.e. return)
        set ( ${ModuleType}_SRCS ${${ModuleType}_SRCS} PARENT_SCOPE )
+       set ( ${ModuleType}Module_KLL ${${ModuleType}Module_KLL} PARENT_SCOPE )
 endfunction ()
 
 
diff --git a/Scan/MatrixARM/capabilities.kll b/Scan/MatrixARM/capabilities.kll
new file mode 100644 (file)
index 0000000..319b81d
--- /dev/null
@@ -0,0 +1,20 @@
+Name = MatrixArmCapabilities;
+Version = 0.1;
+Author = "HaaTa (Jacob Alexander) 2015";
+KLL = 0.3a;
+
+# Modified Date
+Date = 2015-02-28;
+
+# Defines available to the MatrixArm sub-module
+# This debounce scheme uses a rolling counter for press/unpress on each key
+# Each counter is incremented if pressed/unpressed and the opposite counter is divided by 2
+# Using the default division threshold (0xFFFF), there are approximately 13 cycles in a perfect cycle
+# If debounce is actually necessary, this will increase (better switches will debounce faster)
+#
+# The maximum threshold is 0xFFFFFFFF, which will give around ~32 -> 36 cycles per perfect cycle
+# Using a threshold higher than 0xFFFF will require 32 bit variables, and double the ram usage.
+DebounceDivThreshold => DebounceDivThreshold_define;
+DebounceDivThreshold = 0xFFFF; # Default debounce
+#DebounceDivThreshold = 0xFFFFFFFF; # Max debounce
+
index b336efe90117f5f9a7c390ae6e68cc15215005a4..eaea368f4b01e6a8635879e4f9ba1b25e92ca3dc 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2014 by Jacob Alexander
+/* 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
@@ -191,7 +191,7 @@ void Matrix_setup()
                Matrix_scanArray[ item ].prevState     = KeyState_Off;
                Matrix_scanArray[ item ].curState      = KeyState_Off;
                Matrix_scanArray[ item ].activeCount   = 0;
-               Matrix_scanArray[ item ].inactiveCount = 0xFFFF; // Start at 'off' steady state
+               Matrix_scanArray[ item ].inactiveCount = DebounceDivThreshold_define; // Start at 'off' steady state
        }
 
        // Clear scan stats counters
@@ -275,14 +275,14 @@ void Matrix_scan( uint16_t scanNum )
                        if ( Matrix_pin( Matrix_rows[ sense ], Type_Sense ) )
                        {
                                // Only update if not going to wrap around
-                               if ( state->activeCount < 0xFFFF ) state->activeCount += 1;
+                               if ( state->activeCount < DebounceDivThreshold_define ) state->activeCount += 1;
                                state->inactiveCount >>= 1;
                        }
                        // Signal Not Detected
                        else
                        {
                                // Only update if not going to wrap around
-                               if ( state->inactiveCount < 0xFFFF ) state->inactiveCount += 1;
+                               if ( state->inactiveCount < DebounceDivThreshold_define ) state->inactiveCount += 1;
                                state->activeCount >>= 1;
                        }
 
index 487abef27fac7c4346de6e8a52a7eac69e1ba81d..13839a192d88edd69efa29014ca8c122d88583e7 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2014 by Jacob Alexander
+/* 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
 
 // ----- Includes -----
 
+// KLL Generated Defines
+#include <kll_defs.h>
+
+
+
+// ----- Defines -----
+
+#if   ( DebounceDivThreshold_define < 0xFF + 1 )
+#define DebounceCounter uint8_t
+#elif ( DebounceDivThreshold_define < 0xFFFF + 1 )
+#define DebounceCounter uint16_t
+#elif ( DebounceDivThreshold_define < 0xFFFFFFFF + 1 )
+#define DebounceCounter uint32_t
+#else
+#error "Debounce threshold is too high... 32 bit max. Check .kll defines."
+#endif
+
 
 
 // ----- Enums -----
@@ -110,10 +127,10 @@ typedef struct GPIO_Pin {
 
 // Debounce Element
 typedef struct KeyState {
-       KeyPosition prevState;
-       KeyPosition curState;
-       uint16_t activeCount;
-       uint16_t inactiveCount;
+       KeyPosition     prevState;
+       KeyPosition     curState;
+       DebounceCounter activeCount;
+       DebounceCounter inactiveCount;
 } KeyState;