Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Rowan Decker 2015-03-08 20:17:39 -07:00
commit 2922fce0f7
21 changed files with 543 additions and 97 deletions

View file

@ -0,0 +1,34 @@
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
# This defines how often the matrix is scanned
# By, default the key matrix is scanned once per macro processing loop
# For fast uCs and bouncy switches, this can be non-ideal
# 0 - Bit-shift of 0
# 1 - Bit-shift of 1 (i.e. divide by 2)
# 2 - Bit-shift of 2 (i.e. divide by 4)
# 3 - Bit-shift of 3 (i.e. divide by 8)
# etc.
# Depending on the architecture, this is either a maximum of 16 or 32
# Increasing this value will increase switch latency
DebounceThrottleDiv => DebounceThrottleDiv_define;
DebounceThrottleDiv = 0; # Default
#DebounceThrottleDiv = 2; # /4 divider

View 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
@ -26,6 +26,7 @@
// Project Includes
#include <cli.h>
#include <kll.h>
#include <led.h>
#include <print.h>
#include <macro.h>
@ -38,6 +39,14 @@
// ----- Defines -----
#if ( DebounceThrottleDiv_define > 0 )
nat_ptr_t Matrix_divCounter = 0;
#endif
// ----- Function Declarations -----
// CLI Functions
@ -191,7 +200,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
@ -232,6 +241,15 @@ void Matrix_keyPositionDebug( KeyPosition pos )
// NOTE: scanNum should be reset to 0 after a USB send (to reset all the counters)
void Matrix_scan( uint16_t scanNum )
{
#if ( DebounceThrottleDiv_define > 0 )
// Scan-rate throttling
// By scanning using a divider, the scan rate slowed down
// DebounceThrottleDiv_define == 1 means -> /2 or half scan rate
// This helps with bouncy switches on fast uCs
if ( !( Matrix_divCounter++ & (1 << ( DebounceThrottleDiv_define - 1 )) ) )
return;
#endif
// Increment stats counters
if ( scanNum > matrixMaxScans ) matrixMaxScans = scanNum;
if ( scanNum == 0 )
@ -275,14 +293,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;
}

View 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
@ -24,6 +24,23 @@
// ----- 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;