]> git.donarmstrong.com Git - kiibohd-controller.git/blobdiff - Scan/MatrixARM/matrix_scan.h
Adding dynamic USB power support
[kiibohd-controller.git] / Scan / MatrixARM / matrix_scan.h
index 06ae75fbb1b3d5e492f6ee15caf16bbf27e9070a..3a8f0e2ffe8e140de2b65372f5118f58e09ce129 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2014-2015 by Jacob Alexander
+/* Copyright (C) 2014-2016 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
 #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 -----
@@ -126,12 +132,25 @@ typedef struct GPIO_Pin {
 
 // Debounce Element
 typedef struct KeyState {
-       KeyPosition     prevState;
-       KeyPosition     curState;
        DebounceCounter activeCount;
        DebounceCounter inactiveCount;
-} KeyState;
+       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 -----
@@ -139,3 +158,5 @@ typedef struct KeyState {
 void Matrix_setup();
 void Matrix_scan( uint16_t scanNum );
 
+void Matrix_currentChange( unsigned int current );
+