Subversion Repositories group.electronics

Rev

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

Rev 98 Rev 99
Line 18... Line 18...
18
#include "avrutil.h"
18
#include "avrutil.h"
19
#include "lcd.h"
19
#include "lcd.h"
20
#include "wire.h"
20
#include "wire.h"
21
#include "hiddesc.h"
21
#include "hiddesc.h"
22
 
22
 
23
#define BUTTONS	1
23
#define BUTTONS	 	1
24
#define ON		1
24
#define ON		1
25
#define OFF		0
25
#define OFF		0
26
 
26
 
27
// * = 0x25, #=0x20
27
// * = 0x25, #=0x20
28
// F9 = 0x42, F12 = 0x45
28
// F9 = 0x42, F12 = 0x45
Line 44... Line 44...
44
uint8_t getKey(void);
44
uint8_t getKey(void);
45
 
45
 
46
volatile struct {
46
volatile struct {
47
	uint8_t detected;
47
	uint8_t detected;
48
	uint8_t timer;
48
	uint8_t timer;
49
	uint8_t debounced;
49
	uint8_t waitup;
50
} buttons[BUTTONS];
50
} buttons[BUTTONS];
51
 
51
 
52
int main(void)
52
int main(void)
53
{
53
{
54
	
54
	
55
	setup();
55
	setup();
56
	
56
	
57
    while(1)
57
    while(1)
58
    {
58
    {
-
 
59
	wdt_reset();
59
        loop(); 
60
        loop(); 
60
    }
61
    }
61
}
62
}
62
 
63
 
63
void setup() {
64
void setup() {
Line 102... Line 103...
102
	
103
	
103
	usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
104
	usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
104
	_delay_ms(500);
105
	_delay_ms(500);
105
	usbDeviceConnect();
106
	usbDeviceConnect();
106
 
107
 
-
 
108
	sei();
107
	wdt_enable(WDTO_1S);
109
	wdt_enable(WDTO_1S);
108
	usbInit();
110
	usbInit();
109
	usbPoll();
-
 
110
 
111
 
111
	sei();
-
 
112
	i2c_master();
112
	i2c_master();
113
	lcd_init();
113
	lcd_init();
114
	lcd_createChar(0x00, lcdRectangle);
114
	lcd_createChar(0x00, lcdRectangle);
115
	usbPoll();
-
 
116
 
115
 
117
	char strTime[] = {'T', 'i', 'm', 'e', ':', 0x00};
116
	char strTime[] = {'T', 'i', 'm', 'e', ':', 0x00};
118
	lcd_setCursor(0, 1);
117
	lcd_setCursor(0, 1);
119
	lcd_print(strTime);
118
	lcd_print(strTime);
-
 
119
 
-
 
120
	buttons[0].detected = 0;
-
 
121
	buttons[0].timer = 0;
-
 
122
	buttons[0].waitup = 0;
-
 
123
 
-
 
124
	cbi(PORTD, 4);
120
		
125
		
121
}
126
}
122
 
127
 
123
void loop() {
128
void loop() {
-
 
129
 
124
    
130
   	usbPoll(); 
125
	if(usbInterruptIsReady()){
131
	if(usbInterruptIsReady()){
126
	    reportJoystick.data1[0] = (-128 + analogRead(0));
132
	    reportJoystick.data1[0] = (-128 + analogRead(0));
127
	    reportJoystick.data1[1] = (-128 + analogRead(1));
133
	    reportJoystick.data1[1] = (-128 + analogRead(1));
128
	    reportJoystick.data2 = 0x0000;				// Clear all the buttons
134
	    reportJoystick.data2 = 0x0000;				// Clear all the buttons
129
 
135
 
Line 143... Line 149...
143
			    reportKeyboard.keycode = keyMap[--key];
149
			    reportKeyboard.keycode = keyMap[--key];
144
		    }
150
		    }
145
	    }
151
	    }
146
	    usbSendHidReport((uchar*)&reportKeyboard, sizeof(reportKeyboard));
152
	    usbSendHidReport((uchar*)&reportKeyboard, sizeof(reportKeyboard));
147
	    usbSendHidReport((uchar*)&reportJoystick, sizeof(reportJoystick));
153
	    usbSendHidReport((uchar*)&reportJoystick, sizeof(reportJoystick));
148
    }	
154
    	}	
149
}
155
}
150
 
156
 
151
uint8_t getKey() {
157
uint8_t getKey() {
152
	uint8_t col, row = 0;
158
	uint8_t col, row = 0;
153
	uint8_t key = 0;
159
	uint8_t key = 0;
Line 170... Line 176...
170
 
176
 
171
void millis_tick() {
177
void millis_tick() {
172
	if (buttons[0].detected && buttons[0].timer)
178
	if (buttons[0].detected && buttons[0].timer)
173
		buttons[0].timer--;
179
		buttons[0].timer--;
174
	
180
	
175
	//lcdupdate = 1;
-
 
176
}
181
}
177
 
182
 
178
ISR(TIMER0_OVF_vect) {
183
ISR(TIMER0_OVF_vect) {
179
	tmr0_ovf++;
184
	tmr0_ovf++;
180
	if (tmr0_ovf>=sys_ovf_tick) {
185
	if (tmr0_ovf >= sys_ovf_tick) {
181
		systime++;
186
		systime++;
182
		tmr0_ovf = 0;
187
		tmr0_ovf = 0;
-
 
188
		//millis_tick();	// Not working, taking too long to call?
-
 
189
 
-
 
190
		if (buttons[0].detected && buttons[0].timer)
183
		millis_tick();
191
			buttons[0].timer--;
184
	}
192
	}
185
}
193
}
186
 
-
 
187
void usbSendHidReport(uchar * data, uchar len) {
194
void usbSendHidReport(uchar * data, uchar len) {
188
	while(1)
195
	while(1)
189
	{
196
	{
190
		usbPoll();
197
		usbPoll();
191
		if (usbInterruptIsReady())
198
		if (usbInterruptIsReady())
Line 220... Line 227...
220
	}
227
	}
221
	return 0;
228
	return 0;
222
}
229
}
223
 
230
 
224
void hadUsbReset(void) {
231
void hadUsbReset(void) {
225
}
-
 
226
232
}
-
 
233