Archived
1
0

Removed a keyscan layer and added more debug information

- Added a print macro for colourful convenience
- Removed the usb_keymap variable as it is no longer needed
- Changed usb_dirty to keymap_change (more accurate description)
- Removed the dumpkeys function and now detect key changes much sooner as well as displaying error messages more often
- Added a warming up information message and removed its error status (as it's not an error)
This commit is contained in:
Jacob Alexander 2013-11-17 19:17:54 -05:00
parent 6b38cfbaee
commit 3d98028679
2 changed files with 87 additions and 81 deletions

View File

@ -59,24 +59,30 @@
// Special Msg Constructs (Uses VT100 tags)
#define dPrintMsg(colour_code_str,msg,...) \
usb_debug_putstrs("\033[", colour_code_str, "m", msg, "\033[0m - ", __VA_ARGS__, NL, "\0\0\0")
#define printMsg(colour_code_str,msg,str) \
#define printMsgNL(colour_code_str,msg,str) \
print("\033[" colour_code_str "m" msg "\033[0m - " str NL)
#define printMsg(colour_code_str,msg,str) \
print("\033[" colour_code_str "m" msg "\033[0m - " str)
// Info Messages
#define info_dPrint(...) dPrintMsg ("1;32", "INFO", __VA_ARGS__) // Info Msg
#define info_print(str) printMsg ("1;32", "INFO", str) // Info Msg
#define info_print(str) printMsgNL ("1;32", "INFO", str) // Info Msg
#define info_msg(str) printMsg ("1;32", "INFO", str) // Info Msg
// Warning Messages
#define warn_dPrint(...) dPrintMsg ("1;33", "WARNING", __VA_ARGS__) // Warning Msg
#define warn_print(str) printMsg ("1;33", "WARNING", str) // Warning Msg
#define warn_print(str) printMsgNL ("1;33", "WARNING", str) // Warning Msg
#define warn_msg(str) printMsg ("1;33", "WARNING", str) // Warning Msg
// Error Messages
#define erro_dPrint(...) dPrintMsg ("1;5;31", "ERROR", __VA_ARGS__) // Error Msg
#define erro_print(str) printMsg ("1;5;31", "ERROR", str) // Error Msg
#define erro_print(str) printMsgNL ("1;5;31", "ERROR", str) // Error Msg
#define erro_msg(str) printMsg ("1;5;31", "ERROR", str) // Error Msg
// Debug Messages
#define dbug_dPrint(...) dPrintMsg ("1;35", "DEBUG", __VA_ARGS__) // Debug Msg
#define dbug_print(str) printMsg ("1;35", "DEBUG", str) // Debug Msg
#define dbug_print(str) printMsgNL ("1;35", "DEBUG", str) // Debug Msg
#define dbug_msg(str) printMsg ("1;35", "DEBUG", str) // Debug Msg
// Static String Printing

View File

@ -88,6 +88,7 @@
#define MUXES_COUNT_XSHIFT 3
#define WARMUP_LOOPS ( 1024 )
#define WARMUP_STOP (WARMUP_LOOPS - 1)
#define SAMPLES 10
#define SAMPLE_OFFSET ((SAMPLES) - MUXES_COUNT)
@ -150,9 +151,8 @@ uint16_t adc_mux_averages [MUXES_COUNT];
uint16_t adc_strobe_averages[STROBE_LINES];
uint8_t cur_keymap[STROBE_LINES];
uint8_t usb_keymap[STROBE_LINES];
uint8_t usb_dirty;
uint8_t keymap_change;
uint16_t threshold = 0x25; // HaaTa Hack -TODO
//uint16_t threshold = 0x16; // HaaTa Hack -TODO
@ -162,7 +162,6 @@ uint8_t column = 0;
uint16_t keys_averages_acc[KEY_COUNT];
uint16_t keys_averages[KEY_COUNT];
uint16_t keys_averages_acc_count=0;
uint8_t full_samples[KEY_COUNT];
@ -188,8 +187,7 @@ uint16_t db_threshold = 0;
// ----- Function Declarations -----
void dump ( void );
void dumpkeys( void );
void dump( void );
void recovery( uint8_t on );
@ -222,7 +220,6 @@ inline void scan_setup()
// TODO all this code should probably be in scan_resetKeyboard
for (int i=0; i < STROBE_LINES; ++i) {
cur_keymap[i] = 0;
usb_keymap[i] = 0;
}
for(int i=0; i < MUXES_COUNT; ++i) {
@ -269,10 +266,26 @@ inline uint8_t scan_loop()
if( column != cur_keymap[strober] && ( boot_count >= WARMUP_LOOPS ) )
{
cur_keymap[strober] = column;
usb_dirty = 1;
keymap_change = 1;
// The keypresses on this strobe are now know, send them right away
for ( uint8_t mux = 0; mux < MUXES_COUNT; ++mux )
{
if ( column & (1 << mux) )
{
uint8_t key = (strober << MUXES_COUNT_XSHIFT) + mux;
// Add to the Macro processing buffer
// Automatically handles converting to a USB code and sending off to the PC
//bufferAdd( key );
printHex( key );
print("\n");
}
}
}
idle |= usb_dirty; // if any keys have changed inc. released, then we are not idle.
idle |= keymap_change; // if any keys have changed inc. released, then we are not idle.
if ( error == 0x50 )
{
@ -287,7 +300,6 @@ inline uint8_t scan_loop()
full_samples[strobe_line + i] = sample;
keys_averages_acc[strobe_line + i] += sample;
}
keys_averages_acc_count++;
strobe_averages[strober] = 0;
for ( uint8_t i = SAMPLE_OFFSET; i < ( SAMPLE_OFFSET + MUXES_COUNT ); ++i )
@ -348,28 +360,44 @@ inline uint8_t scan_loop()
idle_count++;
idle_count &= IDLE_COUNT_MASK;
// Warm up voltage references
if ( boot_count < WARMUP_LOOPS )
{
error = 0x0C;
error_data = boot_count;
boot_count++;
switch ( boot_count )
{
// First loop
case 1:
// Show msg at first iteration only
info_msg("Warming up the voltage references");
break;
// Middle iterations
case 300:
case 600:
case 900:
case 1200:
print(".");
break;
// Last loop
case WARMUP_STOP:
print("\n");
info_msg("Warmup finished using ");
printInt16( WARMUP_LOOPS );
print(" iterations\n");
break;
}
}
else
{
if ( usb_dirty )
// Reset accumulators and idle flag/counter
if ( keymap_change )
{
for ( int i = 0; i < STROBE_LINES; ++i )
{
usb_keymap[i] = cur_keymap[i];
}
dumpkeys();
usb_dirty = 0;
memset(((void *)keys_averages_acc), 0, (size_t)(KEY_COUNT * sizeof (uint16_t)));
keys_averages_acc_count = 0;
for ( uint8_t c = 0; c < KEY_COUNT; ++c ) { keys_averages_acc[c] = 0; }
idle_count = 0;
idle = 0;
_delay_us(100);
keymap_change = 0;
}
if ( !idle_count )
@ -389,7 +417,6 @@ inline uint8_t scan_loop()
keys_averages_acc[i] = 0;
}
}
keys_averages_acc_count = 0;
if ( boot_count >= WARMUP_LOOPS )
{
@ -401,6 +428,32 @@ inline uint8_t scan_loop()
}
// Error case, should not occur in normal operation
if ( error )
{
erro_msg("Problem detected... ");
// Keymap scan debug
for ( uint8_t i = 0; i < STROBE_LINES; ++i )
{
printHex(cur_keymap[i]);
print(" ");
}
print(" : ");
printHex(error);
error = 0;
print(" : ");
printHex(error_data);
error_data = 0;
// Display keymaps and other debug information if warmup completede
if ( boot_count >= WARMUP_LOOPS )
{
dump();
}
}
// Return non-zero if macro and USB processing should be delayed
// Macro processing will always run if returning 0
@ -880,59 +933,6 @@ uint8_t testColumn( uint8_t strobe )
}
void dumpkeys()
{
if ( error )
{
erro_print("Problem detected...");
if ( boot_count >= WARMUP_LOOPS )
{
dump();
}
// Key scan debug
for ( uint8_t i = 0; i < STROBE_LINES; ++i )
{
printHex(usb_keymap[i]);
print(" ");
}
print(" : ");
printHex(error);
error = 0;
print(" : ");
printHex(error_data);
error_data = 0;
print(" : " NL);
}
// XXX Will be cleaned up eventually, but this will do for now :P -HaaTa
for ( uint8_t i = 0; i < STROBE_LINES; ++i )
{
for ( uint8_t j = 0; j < MUXES_COUNT; ++j )
{
if ( usb_keymap[i] & (1 << j) )
{
uint8_t key = (i << MUXES_COUNT_XSHIFT) + j;
// Add to the Macro processing buffer
// Automatically handles converting to a USB code and sending off to the PC
//bufferAdd( key );
if ( usb_dirty )
{
printHex( key );
print("\n");
}
}
}
}
usb_keyboard_send();
}
void dump(void) {
#ifdef DEBUG_FULL_SAMPLES_AVERAGES