Pārlūkot izejas kodu

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)
simple
Jacob Alexander pirms 10 gadiem
vecāks
revīzija
3d98028679
2 mainītis faili ar 87 papildinājumiem un 81 dzēšanām
  1. 11
    5
      Debug/print/print.h
  2. 76
    76
      Scan/avr-capsense/scan_loop.c

+ 11
- 5
Debug/print/print.h Parādīt failu

// Special Msg Constructs (Uses VT100 tags) // Special Msg Constructs (Uses VT100 tags)
#define dPrintMsg(colour_code_str,msg,...) \ #define dPrintMsg(colour_code_str,msg,...) \
usb_debug_putstrs("\033[", colour_code_str, "m", msg, "\033[0m - ", __VA_ARGS__, NL, "\0\0\0") 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) 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 // Info Messages
#define info_dPrint(...) dPrintMsg ("1;32", "INFO", __VA_ARGS__) // Info Msg #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 // Warning Messages
#define warn_dPrint(...) dPrintMsg ("1;33", "WARNING", __VA_ARGS__) // Warning Msg #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 // Error Messages
#define erro_dPrint(...) dPrintMsg ("1;5;31", "ERROR", __VA_ARGS__) // Error Msg #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 // Debug Messages
#define dbug_dPrint(...) dPrintMsg ("1;35", "DEBUG", __VA_ARGS__) // Debug Msg #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 // Static String Printing

+ 76
- 76
Scan/avr-capsense/scan_loop.c Parādīt failu

#define MUXES_COUNT_XSHIFT 3 #define MUXES_COUNT_XSHIFT 3


#define WARMUP_LOOPS ( 1024 ) #define WARMUP_LOOPS ( 1024 )
#define WARMUP_STOP (WARMUP_LOOPS - 1)


#define SAMPLES 10 #define SAMPLES 10
#define SAMPLE_OFFSET ((SAMPLES) - MUXES_COUNT) #define SAMPLE_OFFSET ((SAMPLES) - MUXES_COUNT)
uint16_t adc_strobe_averages[STROBE_LINES]; uint16_t adc_strobe_averages[STROBE_LINES];


uint8_t cur_keymap[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 = 0x25; // HaaTa Hack -TODO
//uint16_t threshold = 0x16; // HaaTa Hack -TODO //uint16_t threshold = 0x16; // HaaTa Hack -TODO


uint16_t keys_averages_acc[KEY_COUNT]; uint16_t keys_averages_acc[KEY_COUNT];
uint16_t keys_averages[KEY_COUNT]; uint16_t keys_averages[KEY_COUNT];
uint16_t keys_averages_acc_count=0;


uint8_t full_samples[KEY_COUNT]; uint8_t full_samples[KEY_COUNT];




// ----- Function Declarations ----- // ----- Function Declarations -----


void dump ( void );
void dumpkeys( void );
void dump( void );


void recovery( uint8_t on ); void recovery( uint8_t on );


// TODO all this code should probably be in scan_resetKeyboard // TODO all this code should probably be in scan_resetKeyboard
for (int i=0; i < STROBE_LINES; ++i) { for (int i=0; i < STROBE_LINES; ++i) {
cur_keymap[i] = 0; cur_keymap[i] = 0;
usb_keymap[i] = 0;
} }


for(int i=0; i < MUXES_COUNT; ++i) { for(int i=0; i < MUXES_COUNT; ++i) {
if( column != cur_keymap[strober] && ( boot_count >= WARMUP_LOOPS ) ) if( column != cur_keymap[strober] && ( boot_count >= WARMUP_LOOPS ) )
{ {
cur_keymap[strober] = column; 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 ) if ( error == 0x50 )
{ {
full_samples[strobe_line + i] = sample; full_samples[strobe_line + i] = sample;
keys_averages_acc[strobe_line + i] += sample; keys_averages_acc[strobe_line + i] += sample;
} }
keys_averages_acc_count++;


strobe_averages[strober] = 0; strobe_averages[strober] = 0;
for ( uint8_t i = SAMPLE_OFFSET; i < ( SAMPLE_OFFSET + MUXES_COUNT ); ++i ) for ( uint8_t i = SAMPLE_OFFSET; i < ( SAMPLE_OFFSET + MUXES_COUNT ); ++i )
idle_count++; idle_count++;
idle_count &= IDLE_COUNT_MASK; idle_count &= IDLE_COUNT_MASK;


// Warm up voltage references
if ( boot_count < WARMUP_LOOPS ) if ( boot_count < WARMUP_LOOPS )
{ {
error = 0x0C;
error_data = boot_count;
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 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_count = 0;
idle = 0; idle = 0;
_delay_us(100);

keymap_change = 0;
} }


if ( !idle_count ) if ( !idle_count )
keys_averages_acc[i] = 0; keys_averages_acc[i] = 0;
} }
} }
keys_averages_acc_count = 0;


if ( boot_count >= WARMUP_LOOPS ) if ( boot_count >= WARMUP_LOOPS )
{ {


} }


// 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 // Return non-zero if macro and USB processing should be delayed
// Macro processing will always run if returning 0 // Macro processing will always run if returning 0
} }




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) { void dump(void) {


#ifdef DEBUG_FULL_SAMPLES_AVERAGES #ifdef DEBUG_FULL_SAMPLES_AVERAGES