Changeset c8ec8ce in avrstuff
- Timestamp:
- Sep 3, 2012, 11:08:47 PM (12 years ago)
- Branches:
- main
- Children:
- 41d46ae
- Parents:
- 8659a17
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
V-USB_Dev/firmwares/herePic/main.c
r8659a17 rc8ec8ce 27 27 #define VPP 1 28 28 29 // VUSB leds (PD6 and PD7) 30 #define RED 64 31 #define GREEN 128 29 32 30 33 // TODO is it wise to use a timer or two for bit patterns generation ? (see … … 56 59 PORTB |= VPP; // Enter programming mode 57 60 61 // Configure leds 62 DDRD |= RED | GREEN; 63 PORTD |= RED | GREEN; 64 65 int k = 0; 66 58 67 while(1) { 68 if (k-- < 0) 69 { 70 k = 20000; 71 PORTD ^= RED; 72 } 59 73 wdt_reset(); 60 74 usbPoll(); … … 67 81 for(int i = 6; --i>= 0;) 68 82 { 69 PORTB |= PGC;70 83 if(cmd & 1) 71 84 PORTB |= PGD; 72 85 else 73 86 PORTB &= ~PGD; 87 PORTB |= PGC; 74 88 PORTB &= ~PGC; 75 89 … … 88 102 for(int i = 16; --i>= 0;) 89 103 { 90 PORTB |= PGC;91 104 if(data & 1) 92 105 PORTB |= PGD; 93 106 else 94 107 PORTB &= ~PGD; 108 PORTB |= PGC; 95 109 PORTB &= ~PGC; 96 110 … … 105 119 ICSP_command(cmd); 106 120 121 // PGD as input 122 DDRB &= ~PGD; 123 PORTB |= PGD; //pull up 124 107 125 // get data 108 126 for(int i = 16; --i>= 0;) 109 127 { 110 128 PORTB |= PGC; 111 *data |= (P ORTB & PGD) / PGD;129 *data |= (PINB & PGD) / PGD; 112 130 PORTB &= ~PGC; 113 131 … … 115 133 } 116 134 _delay_us(1); 135 136 // PGD as output 137 PORTB &= ~PGD; 138 DDRB |= PGD; 117 139 } 118 140 … … 121 143 usbRequest_t *rq = (void *)data; 122 144 145 PORTD &= ~GREEN; 146 147 if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_VENDOR) 123 148 switch(rq->bRequest) 124 149 { … … 138 163 139 164 // Return the number of bytes we wrote (none here) 165 PORTD |= GREEN; 140 166 return 0; 141 167 } … … 153 179 154 180 // send the command 155 ICSP_command(command); 156 181 ICSP_write(command, 0); 182 183 PORTD |= GREEN; 157 184 return 0; 158 185 } … … 167 194 usbMsgPtr = (uint8_t*)&ICSP_data; 168 195 196 PORTD |= GREEN; 169 197 return 2; // We send 2 bytes back 170 198 } 171 199 } 200 201 // Unhandled commands leave the green led on. 172 202 return 0; 173 203 }
Note:
See TracChangeset
for help on using the changeset viewer.