Subversion Repositories group.NITPanels

Rev

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

Rev 2 Rev 9
Line 17... Line 17...
17
#define NULL    ((void *)0)
17
#define NULL    ((void *)0)
18
#endif
18
#endif
19
 
19
 
20
#define DISPLAYS_ATTACHED 2
20
#define DISPLAYS_ATTACHED 2
21
#define INPUT_REFRESH 50
21
#define INPUT_REFRESH 50
-
 
22
#define FULL_REFRESH  10
22
 
23
 
23
#define I2C_GET_VERSION			0x01
24
#define I2C_GET_VERSION			0x01
24
#define I2C_SET_DEBUG			0x03
25
#define I2C_SET_DEBUG			0x03
25
#define I2C_SET_DIGITS			0x05
26
#define I2C_SET_DIGITS			0x05
26
#define I2C_SET_DECIMAL_PTS		0x08
27
#define I2C_SET_DECIMAL_PTS		0x08
Line 30... Line 31...
30
 
31
 
31
#define USB_GET_VERSION		01
32
#define USB_GET_VERSION		01
32
#define USB_SET_LATCH			20
33
#define USB_SET_LATCH			20
33
#define USB_SET_DISPLAY1		21
34
#define USB_SET_DISPLAY1		21
34
#define USB_SET_DISPLAY2		22
35
#define USB_SET_DISPLAY2		22
-
 
36
#define USB_SET_POINTS			23
35
#define USB_GET_INPUT			30
37
#define USB_GET_INPUT			30
36
 
38
 
37
 
39
 
38
void usbEventResetReady(void);
40
void usbEventResetReady(void);
39
static void calibrateOscillator(void);
41
static void calibrateOscillator(void);
Line 45... Line 47...
45
	uint8_t address;
47
	uint8_t address;
46
	uint8_t value[10];
48
	uint8_t value[10];
47
	uint16_t decpts;
49
	uint16_t decpts;
48
	uint16_t version;	// HB = HW, LB = SW
50
	uint16_t version;	// HB = HW, LB = SW
49
 
51
 
-
 
52
	uint8_t refresh;	// Decimal point refresh
-
 
53
 
50
	int8_t rotary;		// State of the rotary encoder
54
	int8_t rotary;		// State of the rotary encoder
51
	uint8_t buttons;	// State of the buttons
55
	uint8_t buttons;	// State of the buttons
52
} display[DISPLAYS_ATTACHED];
56
} display[DISPLAYS_ATTACHED];
53
 
57
 
54
 
58
 
Line 99... Line 103...
99
 
103
 
100
    // Setup the display data, blank each display
104
    // Setup the display data, blank each display
101
    uint8_t i;
105
    uint8_t i;
102
    for (i=0; i<DISPLAYS_ATTACHED; i++) {
106
    for (i=0; i<DISPLAYS_ATTACHED; i++) {
103
    	display[i].address = 0x26 + i;
107
    	display[i].address = 0x26 + i;
104
    	display[i].decpts = 0x00;
108
    	display[i].decpts = 0x0000;
-
 
109
    	display[i].refresh = 0;
105
 
110
 
106
    	uint8_t j;
111
    	uint8_t j;
107
    	for (j=0; j<10; j++)
112
    	for (j=0; j<10; j++)
108
    		display[i].value[j] = 0x0a;
113
    		display[i].value[j] = 0x0a;
109
    	updateDisplay(i);
114
    	updateDisplay(i);
Line 119... Line 124...
119
    	if (latchDisplay != 255) {
124
    	if (latchDisplay != 255) {
120
    		updateDisplay(latchDisplay);
125
    		updateDisplay(latchDisplay);
121
    		latchDisplay = 255;
126
    		latchDisplay = 255;
122
    	}
127
    	}
123
 
128
 
-
 
129
    	for (i=0; i<DISPLAYS_ATTACHED; i++) {
-
 
130
    		if (display[i].refresh) {
-
 
131
    			i2cbb_Init();
-
 
132
				i2cbb_Start();
-
 
133
				i2cbb_Write( display[i].address << 1 );
-
 
134
				i2cbb_Write( I2C_SET_DECIMAL_PTS );
-
 
135
				i2cbb_Write((uint8_t)(display[i].decpts>>8));
-
 
136
				i2cbb_Write((uint8_t)display[i].decpts);
-
 
137
				i2cbb_Stop();
-
 
138
				display[i].refresh = 0;
-
 
139
    		}
-
 
140
 
-
 
141
    	}
-
 
142
 
124
    	// Refresh time for getting user input data
143
    	// Refresh time for getting user input data
125
		if (systime > refresh) {
144
		if (systime > refresh) {
126
			refresh = systime + INPUT_REFRESH;
145
			refresh = systime + INPUT_REFRESH;
127
			updateInput();
146
			updateInput();
128
		}
147
		}
Line 203... Line 222...
203
    	if (rbi(display[dis].value[n], 7)) {
222
    	if (rbi(display[dis].value[n], 7)) {
204
    		update = 1;
223
    		update = 1;
205
    		break;
224
    		break;
206
    	}
225
    	}
207
    }
226
    }
-
 
227
 
208
    if (!update) return;
228
    if (!update) return;
209
 
229
 
210
    i2cbb_Init();
230
    i2cbb_Init();
211
    i2cbb_Start();
231
    i2cbb_Start();
212
    i2cbb_Write( display[dis].address << 1);
232
    i2cbb_Write( display[dis].address << 1);
Line 219... Line 239...
219
    		i2cbb_Write( send );
239
    		i2cbb_Write( send );
220
    	}
240
    	}
221
    }
241
    }
222
    i2cbb_Stop();
242
    i2cbb_Stop();
223
 
243
 
224
 
-
 
225
    // Send the decimal point
-
 
226
    if (rbi(display[dis].decpts, 15)) {
-
 
227
		i2cbb_Init();
-
 
228
		i2cbb_Start();
-
 
229
		i2cbb_Write( display[dis].address << 1 );
-
 
230
		i2cbb_Write( I2C_SET_DECIMAL_PTS );
-
 
231
		i2cbb_Write((uint8_t)(display[dis].decpts>>8));
-
 
232
		i2cbb_Write((uint8_t)display[dis].decpts);
-
 
233
		i2cbb_Stop();
-
 
234
    }
-
 
235
 
-
 
236
 
-
 
237
    sbi(PORTB, PB0);
244
    sbi(PORTB, PB0);
238
}
245
}
239
 
246
 
240
// The USB functions to transmit/receive data from USB host.
247
// The USB functions to transmit/receive data from USB host.
241
usbMsgLen_t usbFunctionSetup(uchar data[8])
248
usbMsgLen_t usbFunctionSetup(uchar data[8])
Line 247... Line 254...
247
		case USB_SET_LATCH: {
254
		case USB_SET_LATCH: {
248
			latchDisplay = rq->wValue.bytes[0];;
255
			latchDisplay = rq->wValue.bytes[0];;
249
			break;
256
			break;
250
		}
257
		}
251
 
258
 
-
 
259
		case USB_SET_POINTS: {
-
 
260
			display[0].decpts = rq->wValue.word;
-
 
261
			display[1].decpts = rq->wIndex.word;
-
 
262
 
-
 
263
			display[0].refresh = 1;
-
 
264
			display[1].refresh = 1;
-
 
265
		}
-
 
266
 
252
		// Sets the display boards digit buffer. Only on display
267
		// Sets the display boards digit buffer. Only on display
253
		//  board is updated per request. Also does decimal points
268
		//  board is updated per request. Also does decimal points
254
		case USB_SET_DISPLAY1: {
269
		case USB_SET_DISPLAY1: {
255
			uint8_t dis = rq->wValue.bytes[1];
270
			uint8_t dis = rq->wValue.bytes[1];
256
			uint8_t dig = rq->wValue.bytes[0];
271
			uint8_t dig = rq->wValue.bytes[0];
257
			uint8_t dp = rq->wIndex.bytes[1];
-
 
258
			uint8_t val = rq->wIndex.bytes[0];
272
			uint8_t val = rq->wIndex.bytes[0];
259
 
273
 
260
 
-
 
261
			if ((display[dis].value[dig] & 0x0f) != val) {
274
			if ((display[dis].value[dig] & 0x0f) != val) {
262
				display[dis].value[dig] = val;
275
				display[dis].value[dig] = val;
263
				sbi(display[dis].value[dig], 7);
276
				sbi(display[dis].value[dig], 7);
264
			}
277
			}
265
 
-
 
266
			if (dp) {
-
 
267
				sbi(display[dis].decpts, 1 << dig);
-
 
268
			} else {
-
 
269
				cbi(display[dis].decpts, 1 << dig);
-
 
270
			}
-
 
271
 
-
 
272
			break;
278
			break;
273
		}
279
		}
274
 
280
 
275
		// Return the user input data all at once. Its populated from
281
		// Return the user input data all at once. Its populated from
276
		//  buffered data from the updateInput() function.
282
		//  buffered data from the updateInput() function.