Subversion Repositories group.electronics

Rev

Rev 101 | Rev 103 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 101 Rev 102
Line 26... Line 26...
26
#define ROTARYS			1
26
#define ROTARYS			1
27
 
27
 
28
#define LCD_UPDATE		11
28
#define LCD_UPDATE		11
29
#define	ROTARY_UPDATE	5
29
#define	ROTARY_UPDATE	5
30
 
30
 
31
 
-
 
-
 
31
void pcInterrupt(uint8_t);
32
uint8_t getKey(void);
32
uint8_t getKey(void);
33
void updateLcd();
33
void updateLcd();
34
void checkRotarys();
34
void checkRotarys();
35
void checkButtons(void);
35
void checkButtons(void);
36
 
36
 
Line 60... Line 60...
60
//  don't kick of it the same loop run
60
//  don't kick of it the same loop run
61
volatile uint8_t lcdTimer = 8;
61
volatile uint8_t lcdTimer = 8;
62
volatile uint8_t rotaryTimer = 5;
62
volatile uint8_t rotaryTimer = 5;
63
 
63
 
64
volatile struct {
64
volatile struct {
-
 
65
        uint8_t current;
-
 
66
        uint8_t last;
-
 
67
        uint8_t mask;
-
 
68
} pcInt[3];
-
 
69
 
-
 
70
volatile struct {
65
	uint8_t detected;
71
	uint8_t detected;
66
	uint8_t timer;
72
	uint8_t timer;
67
	uint8_t waitup;
73
	uint8_t waitup;
68
} buttons[BUTTONS];
74
} buttons[BUTTONS];
69
 
75
 
Line 167... Line 173...
167
	if (rotaryTimer==0) {
173
	if (rotaryTimer==0) {
168
		checkRotarys();
174
		checkRotarys();
169
		rotaryTimer = ROTARY_UPDATE;
175
		rotaryTimer = ROTARY_UPDATE;
170
	}
176
	}
171
	
177
	
-
 
178
	
172
	checkButtons();
179
	checkButtons();
173
 
180
 
174
 
181
 
175
	if(usbInterruptIsReady()){
182
	if(usbInterruptIsReady()){
176
	    usbSendHidReport((uchar*)&reportKeyboard, sizeof(reportKeyboard));
183
	    usbSendHidReport((uchar*)&reportKeyboard, sizeof(reportKeyboard));
Line 216... Line 223...
216
		} else {
223
		} else {
217
			rotary[rot].sent = 0;
224
			rotary[rot].sent = 0;
218
		}
225
		}
219
		rotary[rot].stat = 0;
226
		rotary[rot].stat = 0;
220
 
227
 
-
 
228
		// tha fuck is this?
221
		if (rbi(PINB, PB4))
229
		//if (rbi(PINB, PB4))
222
			rotary[rot].sent = 0;
230
		//	rotary[rot].sent = 0;
223
	}
231
	}
224
}
232
}
225
 
233
 
226
void checkButtons() {
234
void checkButtons() {
227
 
235
 
Line 248... Line 256...
248
 
256
 
249
	// Only one button for now
257
	// Only one button for now
250
	if (rbi(PINB, 5) == 0 && buttons[0].detected == 0 && buttons[0].timer == 0) {
258
	if (rbi(PINB, 5) == 0 && buttons[0].detected == 0 && buttons[0].timer == 0) {
251
		buttons[0].detected = 1;
259
		buttons[0].detected = 1;
252
		buttons[0].timer = 5;
260
		buttons[0].timer = 5;
253
		
261
		buttons[0].waitup = 0;
254
	}
262
	}
255
	
263
	
256
	if (rbi(PINB, 5) == 1 && buttons[0].waitup == 1) {
264
	if (rbi(PINB, 5) == 1 && buttons[0].waitup == 1) {
257
		buttons[0].detected = 0;
265
		buttons[0].detected = 0;
258
		buttons[0].timer = 0;
266
		buttons[0].timer = 0;
Line 297... Line 305...
297
 
305
 
298
void millis_tick() {
306
void millis_tick() {
299
	
307
	
300
}
308
}
301
 
309
 
-
 
310
/*
-
 
311
 *
-
 
312
 * Process the Pin Change Interrupt.
-
 
313
 * pcint provides what bank caused the interrupt
-
 
314
 *
-
 
315
 */
-
 
316
void pcInterrupt(uint8_t pcint) {
-
 
317
 
-
 
318
        switch (pcint) {
-
 
319
                case 0: pcInt[pcint].current = PINB; break;
-
 
320
                case 1: pcInt[pcint].current = PIND; break;
-
 
321
                case 2: pcInt[pcint].current = PINC; break;
-
 
322
        }
-
 
323
        //pcInt[pcint].current = PIND;
-
 
324
        pcInt[pcint].mask = pcInt[pcint].current ^ pcInt[pcint].last;
-
 
325
        pcInt[pcint].last = pcInt[pcint].current;
-
 
326
 
-
 
327
        // Select what rotary we are dealing with
-
 
328
        //   based on the pc interrupt that fired.
-
 
329
        uint8_t rot = 0;
-
 
330
        if (pcint == 1) 
-
 
331
                rot = 1;
-
 
332
 
-
 
333
        // If rot stat is not 0, we havn't sent
-
 
334
        //  our last results yet. Skip this click.
-
 
335
        if (rotary[rot].stat != 0) {
-
 
336
                pcInt[pcint].mask = 0;
-
 
337
                return;
-
 
338
        }
-
 
339
        // Check which pin caused the interrupt. If they both
-
 
340
        //  equal 0, the pin that interrupted is the direction
-
 
341
        if (rbi(pcInt[pcint].current, PCINT17) == 0 
-
 
342
                && rbi(pcInt[pcint].current, PCINT17) == 0 
-
 
343
                && rbi(pcInt[pcint].mask, PCINT16) ) {
-
 
344
                        rotary[rot].stat = 1;
-
 
345
        } else if (rbi(pcInt[pcint].current, PCINT16) == 0 
-
 
346
                && rbi(pcInt[pcint].current, PCINT17) == 0 
-
 
347
                && rbi(pcInt[pcint].mask, PCINT17) ) {
-
 
348
                        rotary[rot].stat = 2;
-
 
349
        }
-
 
350
 
-
 
351
        // Clear the mask so we know we've delth with it
-
 
352
        pcInt[pcint].mask = 0;
-
 
353
}
-
 
354
 
302
ISR(TIMER0_OVF_vect) {
355
ISR(TIMER0_OVF_vect) {
303
	tmr0_ovf++;
356
	tmr0_ovf++;
304
	if (tmr0_ovf >= sys_ovf_tick) {
357
	if (tmr0_ovf >= sys_ovf_tick) {
305
		systime++;
358
		systime++;
306
		tmr0_ovf = 0;
359
		tmr0_ovf = 0;
Line 315... Line 368...
315
		if (rotaryTimer)
368
		if (rotaryTimer)
316
			rotaryTimer--;
369
			rotaryTimer--;
317
 
370
 
318
	}
371
	}
319
}
372
}
-
 
373
 
-
 
374
ISR(PCINT0_vect) {
-
 
375
        pcInterrupt(0);
-
 
376
}
-
 
377
 
-
 
378
ISR(PCINT1_vect) {
-
 
379
        pcInterrupt(1);
-
 
380
}
-
 
381
 
-
 
382
ISR(PCINT2_vect) {
-
 
383
        pcInterrupt(2);
-
 
384
}
-
 
385
 
-
 
386
 
320
void usbSendHidReport(uchar * data, uchar len) {
387
void usbSendHidReport(uchar * data, uchar len) {
321
	while(1)
388
	while(1)
322
	{
389
	{
323
		usbPoll();
390
		usbPoll();
324
		if (usbInterruptIsReady())
391
		if (usbInterruptIsReady())