annotate main.c @ 174:848e1ef8966c

McHCK now working with UART. - Lots of code cleanup for the intialization of all arm chips - Added more gcc flags to help with debugging linker and memory map - Fixed UART initialization for the smaller MCHCK mk20dx128 (different pin mux)
author Jacob Alexander <haata@kiibohd.com>
date Mon, 30 Jun 2014 23:52:24 -0700
parents 7962a42dbda0
children b250056298df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
106
15961894eaeb Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
1 /* Copyright (C) 2011-2014 by Jacob Alexander
15961894eaeb Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
2 *
0
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
4 * of this software and associated documentation files (the "Software"), to deal
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
5 * in the Software without restriction, including without limitation the rights
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
7 * copies of the Software, and to permit persons to whom the Software is
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
8 * furnished to do so, subject to the following conditions:
106
15961894eaeb Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
9 *
0
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
10 * The above copyright notice and this permission notice shall be included in
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
11 * all copies or substantial portions of the Software.
106
15961894eaeb Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
12 *
0
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
19 * THE SOFTWARE.
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
20 */
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
21
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
22 // ----- Includes -----
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
23
67
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
24 // Compiler Includes
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
25 #include <Lib/MainLib.h>
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
26
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
27 // Project Includes
25
c2ef3daf39e1 Cleaning up main.c
Jacob Alexander <haata@users.sf.net>
parents: 24
diff changeset
28 #include <macro.h>
c2ef3daf39e1 Cleaning up main.c
Jacob Alexander <haata@users.sf.net>
parents: 24
diff changeset
29 #include <scan_loop.h>
105
3764d78996a8 More renaming for the USB to Output Module renaming
Jacob Alexander <haata@kiibohd.com>
parents: 72
diff changeset
30 #include <output_com.h>
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
31
106
15961894eaeb Adding basic CLI functionality.
Jacob Alexander <haata@kiibohd.com>
parents: 105
diff changeset
32 #include <cli.h>
25
c2ef3daf39e1 Cleaning up main.c
Jacob Alexander <haata@users.sf.net>
parents: 24
diff changeset
33 #include <led.h>
c2ef3daf39e1 Cleaning up main.c
Jacob Alexander <haata@users.sf.net>
parents: 24
diff changeset
34 #include <print.h>
0
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
35
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
36
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
37
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
38 // ----- Defines -----
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
39
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
40 // Verified Keypress Defines
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
41 #define USB_TRANSFER_DIVIDER 10 // 1024 == 1 Send of keypresses per second, 1 == 1 Send of keypresses per ~1 millisecond
1
0f88e9aad77a Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents: 0
diff changeset
42
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
43
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
44
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
45 // ----- Macros -----
67
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
46 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
47 #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
67
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
48 #endif
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
49
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
50
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
51
111
59391aa888aa Initial Force Gauge CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 106
diff changeset
52 // ----- Function Declarations -----
59391aa888aa Initial Force Gauge CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 106
diff changeset
53
59391aa888aa Initial Force Gauge CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 106
diff changeset
54
59391aa888aa Initial Force Gauge CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 106
diff changeset
55
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
56 // ----- Variables -----
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
57
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
58 // Timer Interrupt for flagging a send of the sampled key detection data to the USB host
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
59 uint16_t sendKeypressCounter = 0;
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
60
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
61 // Flag generated by the timer interrupt
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
62 volatile uint8_t sendKeypresses = 0;
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
63
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
64
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
65
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
66 // ----- Functions -----
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
67
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
68 // Initial Pin Setup, make sure they are sane
174
848e1ef8966c McHCK now working with UART.
Jacob Alexander <haata@kiibohd.com>
parents: 169
diff changeset
69 inline void pinSetup()
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
70 {
27
8b8cad3db8db Basic matrix module for the hall effect keypad now working.
Jacob Alexander <triplehaata@gmail.com>
parents: 26
diff changeset
71
67
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
72 // AVR
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
73 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
74
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
75 // For each pin, 0=input, 1=output
27
8b8cad3db8db Basic matrix module for the hall effect keypad now working.
Jacob Alexander <triplehaata@gmail.com>
parents: 26
diff changeset
76 #if defined(__AVR_AT90USB1286__)
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
77 DDRA = 0x00;
27
8b8cad3db8db Basic matrix module for the hall effect keypad now working.
Jacob Alexander <triplehaata@gmail.com>
parents: 26
diff changeset
78 #endif
5
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
79 DDRB = 0x00;
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
80 DDRC = 0x00;
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
81 DDRD = 0x00;
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
82 DDRE = 0x00;
5
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
83 DDRF = 0x00;
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
84
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
85
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
86 // Setting pins to either high or pull-up resistor
27
8b8cad3db8db Basic matrix module for the hall effect keypad now working.
Jacob Alexander <triplehaata@gmail.com>
parents: 26
diff changeset
87 #if defined(__AVR_AT90USB1286__)
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
88 PORTA = 0x00;
27
8b8cad3db8db Basic matrix module for the hall effect keypad now working.
Jacob Alexander <triplehaata@gmail.com>
parents: 26
diff changeset
89 #endif
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
90 PORTB = 0x00;
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
91 PORTC = 0x00;
24
2d65da455ef3 Formalizing code module structure and inheritance (Large Commit)
Jacob Alexander <triplehaata@gmail.com>
parents: 18
diff changeset
92 PORTD = 0x00;
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
93 PORTE = 0x00;
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
94 PORTF = 0x00;
67
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
95
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
96 // ARM
169
7962a42dbda0 Initial work for McHCK mk20dx128vlf5 port.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
97 #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
72
4c2712f25157 Main USB timer now working, basic Teensy 3 support working.
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
98 // TODO - Should be cleared, but not that necessary due to the pin layout
67
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
99 #endif
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
100 }
7
18e424630cbd Adding basic per line keypad detection
Jacob Alexander <haata@users.sf.net>
parents: 6
diff changeset
101
67
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
102
174
848e1ef8966c McHCK now working with UART.
Jacob Alexander <haata@kiibohd.com>
parents: 169
diff changeset
103 inline void usbTimerSetup()
67
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
104 {
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
105 // AVR
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
106 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
107
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
108 // Setup with 16 MHz clock
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
109 CPU_PRESCALE( 0 );
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
110
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
111 // Setup ISR Timer for flagging a kepress send to USB
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
112 // Set to 256 * 1024 (8 bit timer with Clock/1024 prescalar) timer
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
113 TCCR0A = 0x00;
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
114 TCCR0B = 0x03;
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
115 TIMSK0 = (1 << TOIE0);
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
116
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
117 // ARM
169
7962a42dbda0 Initial work for McHCK mk20dx128vlf5 port.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
118 #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents: 67
diff changeset
119 // 48 MHz clock by default
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents: 67
diff changeset
120
72
4c2712f25157 Main USB timer now working, basic Teensy 3 support working.
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
121 // System Clock Gating Register Disable
4c2712f25157 Main USB timer now working, basic Teensy 3 support working.
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
122 SIM_SCGC6 |= SIM_SCGC6_PIT;
4c2712f25157 Main USB timer now working, basic Teensy 3 support working.
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
123
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents: 67
diff changeset
124 // Enable Timers
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents: 67
diff changeset
125 PIT_MCR = 0x00;
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents: 67
diff changeset
126
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents: 67
diff changeset
127 // Setup ISR Timer for flagging a kepress send to USB
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents: 67
diff changeset
128 // 1 ms / (1 / 48 MHz) - 1 = 47999 cycles -> 0xBB7F
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents: 67
diff changeset
129 PIT_LDVAL0 = 0x0000BB7F;
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents: 67
diff changeset
130 PIT_TCTRL0 = 0x3; // Enable Timer 0 interrupts, and Enable Timer 0
72
4c2712f25157 Main USB timer now working, basic Teensy 3 support working.
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
131
4c2712f25157 Main USB timer now working, basic Teensy 3 support working.
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
132 // Insert the required vector for Timer 0
4c2712f25157 Main USB timer now working, basic Teensy 3 support working.
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
133 NVIC_ENABLE_IRQ( IRQ_PIT_CH0 );
67
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
134 #endif
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
135 }
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
136
174
848e1ef8966c McHCK now working with UART.
Jacob Alexander <haata@kiibohd.com>
parents: 169
diff changeset
137 int main()
0
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
138 {
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
139 // Configuring Pins
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
140 pinSetup();
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
141
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
142 // Enable CLI
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
143 CLI_init();
0
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
144
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
145 // Setup Modules
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
146 Output_setup();
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
147 Macro_setup();
132
e08d7b586ea3 Adding analog.c lib from teensyduino.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
148 Scan_setup();
105
3764d78996a8 More renaming for the USB to Output Module renaming
Jacob Alexander <haata@kiibohd.com>
parents: 72
diff changeset
149
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
150 // Setup ISR Timer for flagging a kepress send to USB
67
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
151 usbTimerSetup();
4
b97797936037 Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents: 3
diff changeset
152
0
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
153 // Main Detection Loop
25
c2ef3daf39e1 Cleaning up main.c
Jacob Alexander <haata@users.sf.net>
parents: 24
diff changeset
154 while ( 1 )
c2ef3daf39e1 Cleaning up main.c
Jacob Alexander <haata@users.sf.net>
parents: 24
diff changeset
155 {
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
156 // Process CLI
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
157 CLI_process();
26
c06a5ebb4fca Tandy 1000 Converter, basicly works, except for packet mismatches
Jacob Alexander <triplehaata@gmail.com>
parents: 25
diff changeset
158
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
159 // Acquire Key Indices
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
160 // Loop continuously until scan_loop returns 0
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
161 cli();
140
98e4f0bc2a5b Added support for IBM 50key, better DPH debug, cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 132
diff changeset
162 while ( Scan_loop() );
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
163 sei();
25
c2ef3daf39e1 Cleaning up main.c
Jacob Alexander <haata@users.sf.net>
parents: 24
diff changeset
164
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
165 // Run Macros over Key Indices and convert to USB Keys
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
166 Macro_process();
26
c06a5ebb4fca Tandy 1000 Converter, basicly works, except for packet mismatches
Jacob Alexander <triplehaata@gmail.com>
parents: 25
diff changeset
167
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
168 // Send keypresses over USB if the ISR has signalled that it's time
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
169 if ( !sendKeypresses )
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
170 continue;
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
171
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
172 // Send USB Data
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents: 123
diff changeset
173 Output_send();
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
174
123
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
175 // Clear sendKeypresses Flag
0c5d1fe99302 Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents: 122
diff changeset
176 sendKeypresses = 0;
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
177 }
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
178 }
0
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
179
67
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
180
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
181 // ----- Interrupts -----
9ad7c1a28661 Preparing for Teensy 3 (ARM) integration, abstracting code hierarchy
Jacob Alexander <triplehaata@gmail.com>
parents: 40
diff changeset
182
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents: 67
diff changeset
183 // USB Keyboard Data Send Counter Interrupt
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents: 67
diff changeset
184 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
185 ISR( TIMER0_OVF_vect )
169
7962a42dbda0 Initial work for McHCK mk20dx128vlf5 port.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
186 #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
174
848e1ef8966c McHCK now working with UART.
Jacob Alexander <haata@kiibohd.com>
parents: 169
diff changeset
187 void pit0_isr()
70
23600aaa5e15 Adding initial Teensy 3 support, compiles, but not fully functional yet.
Jacob Alexander <triplehaata@gmail.com>
parents: 67
diff changeset
188 #endif
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
189 {
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
190 sendKeypressCounter++;
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
191 if ( sendKeypressCounter > USB_TRANSFER_DIVIDER ) {
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
192 sendKeypressCounter = 0;
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
193 sendKeypresses = 1;
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
194 }
72
4c2712f25157 Main USB timer now working, basic Teensy 3 support working.
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
195
169
7962a42dbda0 Initial work for McHCK mk20dx128vlf5 port.
Jacob Alexander <haata@kiibohd.com>
parents: 140
diff changeset
196 #if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) // ARM
72
4c2712f25157 Main USB timer now working, basic Teensy 3 support working.
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
197 // Clear the interrupt flag
4c2712f25157 Main USB timer now working, basic Teensy 3 support working.
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
198 PIT_TFLG0 = 1;
4c2712f25157 Main USB timer now working, basic Teensy 3 support working.
Jacob Alexander <triplehaata@gmail.com>
parents: 70
diff changeset
199 #endif
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
200 }
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
201
111
59391aa888aa Initial Force Gauge CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 106
diff changeset
202
59391aa888aa Initial Force Gauge CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 106
diff changeset
203 // ----- CLI Command Functions -----
59391aa888aa Initial Force Gauge CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 106
diff changeset
204
120
b90e5316ffe7 Adding iGaging support for reading values as mm, um and nm.
Jacob Alexander <haata@kiibohd.com>
parents: 115
diff changeset
205