Subversion Repositories group.electronics

Rev

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

Rev 62 Rev 63
Line 8... Line 8...
8
#include <usbdrv.h>
8
#include <usbdrv.h>
9
 
9
 
10
#include <stdlib.h>
10
#include <stdlib.h>
11
#include <string.h>
11
#include <string.h>
12
 
12
 
-
 
13
#include "lcd.h"
13
#include "util.h"
14
#include "util.h"
14
#include "wire.h"
15
#include "wire.h"
15
#include "config.h"
16
#include "config.h"
16
#include "hiddesc.h"
17
#include "hiddesc.h"
17
 
18
 
Line 41... Line 42...
41
 
42
 
42
 
43
 
43
void doInt(uint8_t pcint);
44
void doInt(uint8_t pcint);
44
uint8_t getKey(void);
45
uint8_t getKey(void);
45
 
46
 
-
 
47
uint8_t oldpotVal = 0;
-
 
48
 
-
 
49
volatile uint8_t tmr0_ovf = 0;
-
 
50
volatile uint8_t tmr2_ovf = 0;
-
 
51
volatile uint32_t systime = 0;
-
 
52
volatile uint8_t lcdupdate = 1;
-
 
53
 
-
 
54
uint8_t emblock[] = {   0B00011111,
-
 
55
                        0B00010001,
-
 
56
                        0B00010001,
-
 
57
                        0B00010001,
-
 
58
                        0B00010001,
-
 
59
                        0B00010001,
-
 
60
                        0B00010001,
-
 
61
                        0B00011111 };
-
 
62
 
-
 
63
 
46
volatile struct {
64
volatile struct {
47
	uint8_t current;
65
	uint8_t current;
48
	uint8_t last;
66
	uint8_t last;
49
	uint8_t mask;
67
	uint8_t mask;
50
} pcInt[3];
68
} pcInt[3];
Line 174... Line 192...
174
 
192
 
175
  // Timers not used for the moment
193
  // Timers not used for the moment
176
  // Setup timer0 - Enable overflow, 8 times prescaler
194
  // Setup timer0 - Enable overflow, 8 times prescaler
177
	TIMSK0 = (1<<TOIE0);			// Eable timer overflow for Timer0
195
	TIMSK0 = (1<<TOIE0);			// Eable timer overflow for Timer0
178
	TCNT0 = 0x00;				// Set Timer0 to 0
196
	TCNT0 = 0x00;				// Set Timer0 to 0
179
	TCCR0B = (1<< CS01) ;			// /8 prescaler
197
	TCCR0B = (1<< CS00) ;			// /1 prescaler
-
 
198
 
-
 
199
	TIMSK2 = (1<<TOIE2);
-
 
200
	TCNT2 = 0x00;
-
 
201
	TCCR2B = (1<<CS21 | 1<<CS20);
180
 
202
 
181
	i2c_master();
203
	i2c_master();
-
 
204
	lcd_init();
-
 
205
	lcd_createChar(0x00, emblock);
182
 
206
 
-
 
207
	char strTime[] = {'T', 'i', 'm', 'e', ':', 0x00};
-
 
208
        lcd_setCursor(0, 1);
-
 
209
        lcd_print(strTime);
-
 
210
 
183
  usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
211
	usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
184
  _delay_ms(500);
212
	_delay_ms(500);
185
  usbDeviceConnect();
213
	usbDeviceConnect();
186
 
214
 
187
  wdt_enable(WDTO_1S);
215
	wdt_enable(WDTO_1S);
188
  usbInit();
216
	usbInit();
189
  sei();
217
	sei();
190
 
218
 
191
	reportKeyboard.report_id = 1;
219
	reportKeyboard.report_id = 1;
192
	reportJoystick.report_id = 2;
220
	reportJoystick.report_id = 2;
193
 
221
 
194
  for(;;) {
222
  for(;;) {
Line 241... Line 269...
241
 
269
 
242
		switches[0][DETECTED] = 2;
270
		switches[0][DETECTED] = 2;
243
		switches[0][DEBOUNCED] = 0;
271
		switches[0][DEBOUNCED] = 0;
244
	}
272
	}
245
	
273
	
246
		
274
	usbPoll();	
247
 
275
 
248
    if(usbInterruptIsReady()){
276
    if(usbInterruptIsReady()){
249
	reportJoystick.data1[0] = (-128 + analogRead(0));
277
	reportJoystick.data1[0] = (-128 + analogRead(0));
250
	reportJoystick.data1[1] = (-128 + analogRead(1));
278
	reportJoystick.data1[1] = (-128 + analogRead(1));
251
	reportJoystick.data2 = 0x0000;				// Clear all the buttons
279
	reportJoystick.data2 = 0x0000;				// Clear all the buttons
Line 300... Line 328...
300
 
328
 
301
	usbSendHidReport(&reportKeyboard, sizeof(reportKeyboard));
329
	usbSendHidReport(&reportKeyboard, sizeof(reportKeyboard));
302
	usbSendHidReport(&reportJoystick, sizeof(reportJoystick));
330
	usbSendHidReport(&reportJoystick, sizeof(reportJoystick));
303
 
331
 
304
    }
332
    }
-
 
333
 
-
 
334
	usbPoll();
-
 
335
	if (lcdupdate) {
-
 
336
		lcdupdate = 0;
-
 
337
 
-
 
338
                char syschar[10];
-
 
339
                ultoa(systime, syschar, 10);
-
 
340
                lcd_overprint_right(syschar, 10, 5, 1);
-
 
341
 
-
 
342
                uint8_t potVal = map_8(analogRead(0), 0, 255, 0, 100);
-
 
343
                if (potVal != oldpotVal) {
-
 
344
                        lcd_percent_graph(potVal, 0, 0);
-
 
345
                        oldpotVal = potVal;
-
 
346
 
-
 
347
                        char pot[3];
-
 
348
                        utoa(potVal, pot, 10);
-
 
349
                        lcd_overprint_right(pot, 3, 11, 0);
-
 
350
 
-
 
351
                        // Set percentage
-
 
352
                        lcd_setCursor(15, 0);
-
 
353
                        lcd_char(0x25);
-
 
354
                }
-
 
355
 
-
 
356
 
-
 
357
	}
-
 
358
 
305
  }
359
  }
306
}
360
}
307
 
361
 
308
uint8_t getKey() {
362
uint8_t getKey() {
309
	uint8_t col, row = 0;
363
	uint8_t col, row = 0;
Line 369... Line 423...
369
	// Clear the mask so we know we've delth with it
423
	// Clear the mask so we know we've delth with it
370
	pcInt[pcint].mask = 0;
424
	pcInt[pcint].mask = 0;
371
}
425
}
372
 
426
 
373
ISR(TIMER0_OVF_vect) {
427
ISR(TIMER0_OVF_vect) {
-
 
428
	tmr0_ovf++;
-
 
429
	if (tmr0_ovf>=46) {
-
 
430
		systime++;
-
 
431
		tmr0_ovf = 0;
-
 
432
	}
374
	if (switches[0][DETECTED] && switches[0][TIMER])
433
	if (switches[0][DETECTED] && switches[0][TIMER])
375
		switches[0][TIMER]--;
434
		switches[0][TIMER]--;
376
}
435
}
377
 
436
 
-
 
437
ISR(TIMER2_OVF_vect) {
-
 
438
        tmr2_ovf++;
-
 
439
        if (tmr2_ovf>=58) {
-
 
440
                lcdupdate=1;
-
 
441
                tmr2_ovf = 0;
-
 
442
        }
-
 
443
}
-
 
444
 
-
 
445
 
378
ISR(PCINT0_vect) {
446
ISR(PCINT0_vect) {
379
	pcInterrupt(0);
447
	pcInterrupt(0);
380
}
448
}
381
 
449
 
382
ISR(PCINT1_vect) {
450
ISR(PCINT1_vect) {