Changeset 5b8c7e2 in avrstuff
- Timestamp:
- Sep 8, 2019, 3:12:32 PM (5 years ago)
- Branches:
- main
- Children:
- 62256f0
- Parents:
- 5b8020c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
grip2hid/main.cpp
r5b8020c r5b8c7e2 17 17 #define GRIP_DAT_B (1 << 3) 18 18 #define GRIP_CLK_B (1 << 2) 19 #define GRIP_DAT_C (1 << 7) 20 #define GRIP_CLK_C (1 << 6) 21 #define GRIP_DAT_D (1 << 5) 22 #define GRIP_CLK_D (1 << 4) 19 23 20 24 class GrIP … … 65 69 66 70 int main() { 67 GrIP pad[2];68 69 71 wdt_enable(WDTO_2S); 70 72 71 // debug LEDs - output72 DDRD |= 0x7C;73 PORTD = 0;74 75 73 // GrIP input 76 GRIP_PORT = 0 ; // Disable pull-ups74 GRIP_PORT = 0xFF; // Enable pull-ups 77 75 GRIP_DDR = 0; // Port as input 78 uint8_t oldv = GRIP_PIN;79 76 80 77 USARTInit(); … … 83 80 USARTWriteChar('\n'); 84 81 82 // Initial value of oldv for edge detection 83 uint8_t oldv = GRIP_PIN; 85 84 86 85 for (;;) { … … 100 99 // should rather use a timer with a known period? 101 100 // Process pad1 101 GrIP pad; 102 102 uint8_t i; 103 103 for (i = 0; i < 255; i++) { … … 110 110 // Read bit 111 111 uint32_t bit = (newv & GRIP_DAT_A) != 0; 112 i = 0; 113 if (pad[0].PushBit(bit)) { 114 pad[0].Dump(); 115 USARTWriteChar(' '); 112 if (pad.PushBit(bit)) { 116 113 break; 117 114 } … … 120 117 oldv = newv; 121 118 } 119 120 pad.Dump(); 121 USARTWriteChar(' '); 122 122 123 123 // Process pad 2 … … 130 130 // Read bit 131 131 uint32_t bit = (newv & GRIP_DAT_B) != 0; 132 i = 0; 133 if (pad[1].PushBit(bit)) { 134 pad[1].Dump(); 135 USARTWriteChar(' '); 132 if (pad.PushBit(bit)) { 136 133 break; 137 134 } … … 140 137 oldv = newv; 141 138 } 139 140 pad.Dump(); 141 USARTWriteChar(' '); 142 143 // Process pad 3 144 for (i = 0; i < 255; i++) { 145 wdt_reset(); 146 147 uint8_t newv = GRIP_PIN; 148 if (!(newv & GRIP_CLK_C)) { // clock is down 149 if (oldv & GRIP_CLK_C) { // and it was up at previous read 150 // Read bit 151 uint32_t bit = (newv & GRIP_DAT_C) != 0; 152 if (pad.PushBit(bit)) { 153 break; 154 } 155 } 156 } 157 oldv = newv; 158 } 159 160 pad.Dump(); 161 USARTWriteChar(' '); 162 163 // Process pad 4 164 for (i = 0; i < 255; i++) { 165 wdt_reset(); 166 167 uint8_t newv = GRIP_PIN; 168 if (!(newv & GRIP_CLK_D)) { // clock is down 169 if (oldv & GRIP_CLK_D) { // and it was up at previous read 170 // Read bit 171 uint32_t bit = (newv & GRIP_DAT_D) != 0; 172 if (pad.PushBit(bit)) { 173 break; 174 } 175 } 176 } 177 oldv = newv; 178 } 179 180 pad.Dump(); 142 181 USARTWriteChar('\r'); 143 182 USARTWriteChar('\n');
Note:
See TracChangeset
for help on using the changeset viewer.