Subversion Repositories group.electronics

Rev

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

Rev 26 Rev 27
Line 13... Line 13...
13
#include "config.h"
13
#include "config.h"
14
#include "hiddesc.h"
14
#include "hiddesc.h"
15
 
15
 
16
 
16
 
17
void doInt(void);
17
void doInt(void);
18
uint8_t getKey(void);
18
int getKey(void);
19
 
19
 
20
volatile uint8_t pcIntCurr = 0;
20
volatile uint8_t pcIntCurr = 0;
21
volatile uint8_t pcIntLast = 0;
21
volatile uint8_t pcIntLast = 0;
22
volatile uint8_t pcIntMask = 0;
22
volatile uint8_t pcIntMask = 0;
23
 
23
 
24
volatile uint8_t rot_stat = 0;
24
volatile uint8_t rot_stat = 0;
25
volatile uint8_t rot_sent = 0;
25
volatile uint8_t rot_sent = 0;
26
 
26
 
27
struct{
27
struct{
28
  union {
28
  union {
29
    uint8_t data[5];	// Rotaries
29
    uint8_t data1[2];	// Rotaries
30
    struct {
30
    struct {
31
	uint8_t rx:8;
31
	uint8_t rx:8;
32
	uint8_t ry:8;
32
	uint8_t ry:8;
-
 
33
    };
-
 
34
  };
-
 
35
 
-
 
36
 
-
 
37
  union {
-
 
38
    uint16_t data2;
-
 
39
    struct {
33
	uint8_t b00:1;
40
	uint8_t b00:1;
34
	uint8_t b01:1;
41
	uint8_t b01:1;
35
	uint8_t b02:1;
42
	uint8_t b02:1;
36
	uint8_t b03:1;
43
	uint8_t b03:1;
37
	uint8_t b04:1;
44
	uint8_t b04:1;
Line 42... Line 49...
42
	uint8_t b09:1;
49
	uint8_t b09:1;
43
	uint8_t b10:1;
50
	uint8_t b10:1;
44
	uint8_t b11:1;
51
	uint8_t b11:1;
45
	uint8_t b12:1;
52
	uint8_t b12:1;
46
	uint8_t b13:1;
53
	uint8_t b13:1;
47
	uint8_t b14:1;
54
	uint8_t rot1a:1;
48
	uint8_t b15:1;
55
	uint8_t rot1b:1;
49
    };
56
    };
50
  };
57
  };
51
} report;
58
} report;
52
 
59
 
53
usbMsgLen_t usbFunctionSetup(uchar data[8]) {
60
usbMsgLen_t usbFunctionSetup(uchar data[8]) {
Line 76... Line 83...
76
  PORT: 1 = Pullup for Input, otherwise set output
83
  PORT: 1 = Pullup for Input, otherwise set output
77
  PIN : Read input pin
84
  PIN : Read input pin
78
  */
85
  */
79
 
86
 
80
  /*
87
  /*
81
	PB0	- Input	 		- Keypad 5
88
	PB0	- Output 		- Keypad 5
82
	PB1	- Input	 		- Keypad 6
89
	PB1	- Output 		- Keypad 6
83
	PB2	- Input	 		- Keypad 7
90
	PB2	- Output 		- Keypad 7
84
	PB3	- Input	 		- Keypad 8
91
	PB3	- Output 		- Keypad 8
85
	PB4	- Input, Pullup		- Function select
92
	PB4	- Input, Pullup		- Function select
86
  */
93
  */
87
  DDRB		= 0B00000000;
94
  DDRB		= 0B00001111;
88
  PORTB 	= 0B00010000;
95
  PORTB 	= 0B00011111;
89
 
96
 
90
  /*
97
  /*
91
	PD0	- Input, Pullup, PCINT16	- Rotary 1a
98
	PD0	- Input, Pullup, PCINT16	- Rotary 1a
92
	PD1	- Input, Pullup, PCINT17	- Rotary 1b
99
	PD1	- Input, Pullup, PCINT17	- Rotary 1b
93
 
100
 
94
 
101
 
95
	PD4	- Output			- Keypad 1
102
	PD4	- Input				- Keypad 1
96
	PD5	- Output			- Keypad 2
103
	PD5	- Input				- Keypad 2
97
	PD6	- Output			- Keypad 3
104
	PD6	- Input				- Keypad 3
98
	PD7	- Output			- Keypad 4
105
	PD7	- Input				- Keypad 4
99
  */
106
  */
100
  DDRD		= 0B11110000;
107
  DDRD		= 0B00000000;
101
  PORTD		= 0B00000011;
108
  PORTD		= 0B11110011;
102
 
109
 
103
  PCMSK2 |= (( 1 << PCINT16 ) | ( 1 << PCINT17 )); //enable encoder pins interrupt sources
110
  PCMSK2 |= (( 1 << PCINT16 ) | ( 1 << PCINT17 )); //enable encoder pins interrupt sources
104
  PCICR |= ( 1 << PCIE2 ); //enable pin change interupts
111
  PCICR |= ( 1 << PCIE2 ); //enable pin change interupts
105
 
112
 
106
  // Timers not used for the moment
113
  // Timers not used for the moment
Line 121... Line 128...
121
  for(;;) {
128
  for(;;) {
122
    wdt_reset();
129
    wdt_reset();
123
    usbPoll();
130
    usbPoll();
124
 
131
 
125
    if(usbInterruptIsReady()){
132
    if(usbInterruptIsReady()){
-
 
133
	report.data1[0] = 0x05;
-
 
134
	report.data1[1] = 0x05;
-
 
135
	report.data2 = 0x0000;
126
 
136
 
-
 
137
	int key = getKey();
-
 
138
	if (key > -1)
127
	report.data[2] |= (1 << getKey());
139
		report.data2 |= (1 << key);
128
 
140
 
129
	// Now work out what rotary to send, if any
141
	// Now work out what rotary to send, if any
130
	// Also record if we sent a positive response, 
142
	// Also record if we sent a positive response, 
131
	//  so we can send a '0' next time (if selected on PD4)
143
	//  so we can send a '0' next time (if selected on PD4)
132
	/*
144
	
133
	if (rot_stat == 0x01 && rot_sent == 0) {
145
	if (rot_stat == 0x01 && rot_sent == 0) {
134
		report.rot1a = 1;
146
		report.rot1a = 1;
135
		rot_sent = 1;
147
		rot_sent = 1;
136
	} else if (rot_stat == 0x02 && rot_sent == 0) {
148
	} else if (rot_stat == 0x02 && rot_sent == 0) {
137
		report.rot1b = 1;
149
		report.rot1b = 1;
138
		rot_sent = 1;
150
		rot_sent = 1;
139
	} else {
151
	} else {
140
		rot_sent = 0;
152
		rot_sent = 0;
141
	}*/
153
	}
142
 
154
 
143
	// Reset our stat so ready for next turn
155
	// Reset our stat so ready for next turn
144
	rot_stat = 0;
156
	rot_stat = 0;
145
 
157
 
146
	// If our function select is set, dont bother
158
	// If our function select is set, dont bother
Line 152... Line 164...
152
      usbSetInterrupt(&report, sizeof(report));
164
      usbSetInterrupt(&report, sizeof(report));
153
    }
165
    }
154
  }
166
  }
155
}
167
}
156
 
168
 
157
uint8_t getKey() {
169
int getKey() {
158
	uint8_t col, row = 0;
170
	uint8_t col, row = 0;
159
	uint8_t key = 0;
171
	int key = -1;
160
	uint8_t n = 0;
172
	uint8_t n = 0;
161
 
173
 
162
	for (col=4; col<=7; col++) {
174
	for (row=0; row<=3; row++) {
-
 
175
		//cbi(DDRB, row);
163
		sbi(PORTD, col);
176
		cbi(PORTB, row);
-
 
177
		_delay_us(100);
164
		for (row=0; row<=3; row++); {
178
		//for (col=4; col<=7; col++); {
165
			if (rbi(PINB, row))
179
			if (rbi(PIND, 4) == 0) key = n;
166
				key = n;
180
			n++;
-
 
181
		        if (rbi(PIND, 5) == 0) key = n;
167
			n++;
182
			n++;
-
 
183
		        if (rbi(PIND, 6) == 0) key = n;
-
 
184
			n++;
-
 
185
		        if (rbi(PIND, 7) == 0) key = n;
-
 
186
			n++;
-
 
187
 
-
 
188
			//if (rbi(PIND, col) == 0)
-
 
189
			//	key = n;
168
		}
190
		//}
-
 
191
		//sbi(DDRB, row);
169
		cbi(PORTD, col);
192
		sbi(PORTB, row);
170
	}
193
	}
171
	return key;
194
	return key;
172
}
195
}
173
 
196
 
174
void doInt() {
197
void doInt() {