]> git.donarmstrong.com Git - kiibohd-controller.git/blobdiff - Scan/MatrixARM/matrix_scan.h
Added support for ghosting matrices and code for elimination.
[kiibohd-controller.git] / Scan / MatrixARM / matrix_scan.h
index bdf727e531abf5c3bf11d20a7e0659be3aa1bd2c..ce09bf18d1a58f4b30ce74e5ad9aab7202dc999c 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
  * THE SOFTWARE.
  */
 
-#ifndef __MATRIX_SCAN_H
-#define __MATRIX_SCAN_H
+#pragma once
 
 // ----- 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
+
+#if   ( MinDebounceTime_define > 0xFF )
+#error "MinDebounceTime is a maximum of 255 ms"
+#elif ( MinDebounceTime_define < 0x00 )
+#error "MinDebounceTime is a minimum 0 ms"
+#endif
+
 
 
 // ----- Enums -----
@@ -110,19 +132,27 @@ typedef struct GPIO_Pin {
 
 // Debounce Element
 typedef struct KeyState {
-       KeyPosition prevState;
-       KeyPosition curState;
-       uint8_t activeCount;
-       uint8_t inactiveCount;
-} KeyState;
+       DebounceCounter activeCount;
+       DebounceCounter inactiveCount;
+       KeyPosition     prevState;
+       KeyPosition     curState;
+       uint8_t         prevDecisionTime;
+} __attribute__((packed)) KeyState;
+
+// Ghost Element, after ghost detection/cancelation
+typedef struct KeyGhost {
+       KeyPosition     prev;
+       KeyPosition     cur;
+       KeyPosition     saved;  // state before ghosting
+} __attribute__((packed)) KeyGhost;
 
+//  utility
+inline uint8_t keyOn(/*KeyPosition*/uint8_t st)
+{      return (st == KeyState_Press || st == KeyState_Hold) ? 1 : 0;   }
 
 
 // ----- Functions -----
 
 void Matrix_setup();
-void Matrix_scan( uint16_t scanNum, uint8_t firstScan );
-
-
-#endif // __MATRIX_SCAN_H
+void Matrix_scan( uint16_t scanNum );