annotate Scan/MDErgo1/scan_loop.c @ 359:b4f66a698f36

Adding preliminary MDErgo keymap - Required updates to CMake in order to handle the multi-layer BaseMaps
author Jacob Alexander <haata@kiibohd.com>
date Thu, 06 Aug 2015 00:36:37 -0700
parents df78f3312db0
children 23a1868b4ac2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
349
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1 /* Copyright (C) 2014-2015 by Jacob Alexander
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
2 *
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
4 * of this software and associated documentation files (the "Software"), to deal
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
5 * in the Software without restriction, including without limitation the rights
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
7 * copies of the Software, and to permit persons to whom the Software is
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
8 * furnished to do so, subject to the following conditions:
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
9 *
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
10 * The above copyright notice and this permission notice shall be included in
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
11 * all copies or substantial portions of the Software.
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
12 *
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
19 * THE SOFTWARE.
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
20 */
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
21
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
22 // ----- Includes -----
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
23
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
24 // Compiler Includes
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
25 #include <Lib/ScanLib.h>
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
26
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
27 // Project Includes
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
28 #include <cli.h>
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
29 #include <connect_scan.h>
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
30 #include <lcd_scan.h>
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
31 #include <led.h>
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
32 #include <led_scan.h>
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
33 #include <print.h>
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
34 #include <matrix_scan.h>
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
35 #include <macro.h>
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
36 #include <output_com.h>
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
37
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
38 // Local Includes
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
39 #include "scan_loop.h"
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
40
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
41
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
42
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
43 // ----- Variables -----
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
44
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
45 // Number of scans since the last USB send
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
46 uint16_t Scan_scanCount = 0;
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
47
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
48
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
49
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
50 // ----- Functions -----
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
51
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
52 // Setup
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
53 inline void Scan_setup()
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
54 {
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
55 // Setup UART Connect, if Output_Available, this is the master node
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
56 Connect_setup( Output_Available );
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
57
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
58 // Setup GPIO pins for matrix scanning
359
b4f66a698f36 Adding preliminary MDErgo keymap
Jacob Alexander <haata@kiibohd.com>
parents: 349
diff changeset
59 Matrix_setup();
349
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
60
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
61 // Setup ISSI chip to control the leds
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
62 LED_setup();
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
63
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
64 // Setup the ST/NHD lcd display
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
65 LCD_setup();
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
66
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
67 // Reset scan count
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
68 Scan_scanCount = 0;
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
69 }
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
70
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
71
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
72 // Main Detection Loop
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
73 inline uint8_t Scan_loop()
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
74 {
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
75 // Scan Matrix
359
b4f66a698f36 Adding preliminary MDErgo keymap
Jacob Alexander <haata@kiibohd.com>
parents: 349
diff changeset
76 Matrix_scan( Scan_scanCount++ );
349
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
77
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
78 // Process any interconnect commands
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
79 Connect_scan();
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
80
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
81 // Process any LED events
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
82 LED_scan();
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
83
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
84 // Process any LCD events
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
85 LCD_scan();
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
86
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
87 return 0;
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
88 }
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
89
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
90
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
91 // Signal from Macro Module that all keys have been processed (that it knows about)
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
92 inline void Scan_finishedWithMacro( uint8_t sentKeys )
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
93 {
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
94 }
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
95
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
96
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
97 // Signal from Output Module that all keys have been processed (that it knows about)
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
98 inline void Scan_finishedWithOutput( uint8_t sentKeys )
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
99 {
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
100 // Reset scan loop indicator (resets each key debounce state)
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
101 // TODO should this occur after USB send or Macro processing?
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
102 Scan_scanCount = 0;
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
103 }
df78f3312db0 Initial commit of MDErgo1
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
104