Subversion Repositories group.electronics

Rev

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

Rev 99 Rev 100
Line 10... Line 10...
10
#include <avr/pgmspace.h>
10
#include <avr/pgmspace.h>
11
#include <avr/interrupt.h>
11
#include <avr/interrupt.h>
12
 
12
 
13
#include <util/delay.h>
13
#include <util/delay.h>
14
#include <avr/wdt.h>
14
#include <avr/wdt.h>
15
#include "usbdrv.h"
15
#include <stdlib.h>
-
 
16
#include <string.h>
16
 
17
 
-
 
18
#include "usbdrv.h"
17
#include "atcpad.h"
19
#include "atcpad.h"
18
#include "avrutil.h"
20
#include "avrutil.h"
19
#include "lcd.h"
21
#include "lcd.h"
20
#include "wire.h"
22
#include "wire.h"
21
#include "hiddesc.h"
23
#include "hiddesc.h"
22
 
24
 
23
#define BUTTONS	 	1
25
#define BUTTONS	 	1
24
#define ON		1
26
#define ON		1
25
#define OFF		0
27
#define OFF		0
26
 
28
 
-
 
29
 
-
 
30
uint8_t getKey(void);
-
 
31
void updateLcd();
-
 
32
 
27
// * = 0x25, #=0x20
33
// * = 0x25, #=0x20
28
// F9 = 0x42, F12 = 0x45
34
// F9 = 0x42, F12 = 0x45
29
uint8_t keyMap[] = { 	0x1E, 0x1F, 0x20,
35
uint8_t keyMap[] = { 	0x1E, 0x1F, 0x20,
30
						0x21, 0x22, 0x23,
36
						0x21, 0x22, 0x23,
31
						0x24, 0x25, 0x26,
37
						0x24, 0x25, 0x26,
32
						0x42, 0x27, 0x45 };
38
						0x42, 0x27, 0x45 };
33
uint8_t keySelect = 1;
-
 
-
 
39
 
34
uint8_t lcdRectangle[] = {   
40
uint8_t lcdRectangle[] = {   
35
	0B00011111,
41
	0B00011111,
36
	0B00010001,
42
	0B00010001,
37
	0B00010001,
43
	0B00010001,
38
	0B00010001,
44
	0B00010001,
39
	0B00010001,
45
	0B00010001,
40
	0B00010001,
46
	0B00010001,
41
	0B00010001,
47
	0B00010001,
42
	0B00011111 };
48
	0B00011111 };
43
 
49
 
-
 
50
 
-
 
51
uint8_t oldpotVal = 0;
-
 
52
volatile uint8_t lcdtimer = 0;
44
uint8_t getKey(void);
53
uint8_t keySelect = 1;
45
 
54
 
46
volatile struct {
55
volatile struct {
47
	uint8_t detected;
56
	uint8_t detected;
48
	uint8_t timer;
57
	uint8_t timer;
49
	uint8_t waitup;
58
	uint8_t waitup;
Line 54... Line 63...
54
	
63
	
55
	setup();
64
	setup();
56
	
65
	
57
    while(1)
66
    while(1)
58
    {
67
    {
59
	wdt_reset();
68
		wdt_reset();
60
        loop(); 
69
        loop(); 
61
    }
70
    }
62
}
71
}
63
 
72
 
64
void setup() {
73
void setup() {
Line 125... Line 134...
125
		
134
		
126
}
135
}
127
 
136
 
128
void loop() {
137
void loop() {
129
 
138
 
130
   	usbPoll(); 
139
   	usbPoll();
-
 
140
 
-
 
141
	if (lcdtimer==0) {
-
 
142
		lcdtimer = 100;
-
 
143
		updateLcd();
-
 
144
	}
-
 
145
 
-
 
146
 
131
	if(usbInterruptIsReady()){
147
	if(usbInterruptIsReady()){
132
	    reportJoystick.data1[0] = (-128 + analogRead(0));
148
	    reportJoystick.data1[0] = (-128 + analogRead(0));
133
	    reportJoystick.data1[1] = (-128 + analogRead(1));
149
	    reportJoystick.data1[1] = (-128 + analogRead(1));
134
	    reportJoystick.data2 = 0x0000;				// Clear all the buttons
150
	    reportJoystick.data2 = 0x0000;				// Clear all the buttons
135
 
151
 
Line 149... Line 165...
149
			    reportKeyboard.keycode = keyMap[--key];
165
			    reportKeyboard.keycode = keyMap[--key];
150
		    }
166
		    }
151
	    }
167
	    }
152
	    usbSendHidReport((uchar*)&reportKeyboard, sizeof(reportKeyboard));
168
	    usbSendHidReport((uchar*)&reportKeyboard, sizeof(reportKeyboard));
153
	    usbSendHidReport((uchar*)&reportJoystick, sizeof(reportJoystick));
169
	    usbSendHidReport((uchar*)&reportJoystick, sizeof(reportJoystick));
154
    	}	
170
    }	
155
}
171
}
156
 
172
 
157
uint8_t getKey() {
173
uint8_t getKey() {
158
	uint8_t col, row = 0;
174
	uint8_t col, row = 0;
159
	uint8_t key = 0;
175
	uint8_t key = 0;
Line 172... Line 188...
172
		sbi(PORTB, row);
188
		sbi(PORTB, row);
173
	}
189
	}
174
	return key;
190
	return key;
175
}
191
}
176
 
192
 
-
 
193
void updateLcd() {
-
 
194
	usbPoll();
-
 
195
	
-
 
196
 
-
 
197
	char syschar[10];
-
 
198
	ultoa(systime, syschar, 10);
-
 
199
	lcd_overprint_right(syschar, 10, 5, 1);
-
 
200
 
-
 
201
	uint8_t potVal = map_8(analogRead(0), 0, 255, 0, 100);
-
 
202
	if (potVal != oldpotVal) {
-
 
203
		lcd_percent_graph(potVal, 0, 0);
-
 
204
		oldpotVal = potVal;
-
 
205
 
-
 
206
		char pot[3];
-
 
207
		utoa(potVal, pot, 10);
-
 
208
		lcd_overprint_right(pot, 3, 11, 0);
-
 
209
 
-
 
210
		// Set percentage
-
 
211
		lcd_setCursor(15, 0);
-
 
212
		lcd_char(0x25);
-
 
213
	}
-
 
214
	
-
 
215
	lcdtimer = 100;
-
 
216
}
-
 
217
 
177
void millis_tick() {
218
void millis_tick() {
178
	if (buttons[0].detected && buttons[0].timer)
219
	if (buttons[0].detected && buttons[0].timer)
179
		buttons[0].timer--;
220
		buttons[0].timer--;
180
	
221
	
181
}
222
}
Line 187... Line 228...
187
		tmr0_ovf = 0;
228
		tmr0_ovf = 0;
188
		//millis_tick();	// Not working, taking too long to call?
229
		//millis_tick();	// Not working, taking too long to call?
189
 
230
 
190
		if (buttons[0].detected && buttons[0].timer)
231
		if (buttons[0].detected && buttons[0].timer)
191
			buttons[0].timer--;
232
			buttons[0].timer--;
-
 
233
			
-
 
234
		if (lcdtimer)
-
 
235
			lcdtimer--;
192
	}
236
	}
193
}
237
}
194
void usbSendHidReport(uchar * data, uchar len) {
238
void usbSendHidReport(uchar * data, uchar len) {
195
	while(1)
239
	while(1)
196
	{
240
	{
Line 207... Line 251...
207
	usbRequest_t *rq = (void *)data;
251
	usbRequest_t *rq = (void *)data;
208
 
252
 
209
	if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) {
253
	if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) {
210
		switch (rq->bRequest) {
254
		switch (rq->bRequest) {
211
			case USBRQ_HID_GET_REPORT:
255
			case USBRQ_HID_GET_REPORT:
212
			if (rq->wValue.bytes[0] == 1)
256
				if (rq->wValue.bytes[0] == 1)
213
			return sizeof(reportKeyboard);
257
					return sizeof(reportKeyboard);
214
			else if (rq->wValue.bytes[0] == 2)
258
				else if (rq->wValue.bytes[0] == 2)
215
			return sizeof(reportJoystick);
259
					return sizeof(reportJoystick);
216
			else
260
				else
217
			return 0;
261
					return 0;
218
			case USBRQ_HID_GET_IDLE:
262
			case USBRQ_HID_GET_IDLE:
219
			usbMsgPtr = &idleRate;
263
				usbMsgPtr = &idleRate;
220
			return 1;
264
			return 1;
221
			
265
			
222
			
266
			
223
			
267
			
224
			default:
268
			default: