Subversion Repositories group.NITPanels

Rev

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

Rev 9 Rev 10
Line 37... Line 37...
37
#define USB_GET_INPUT			30
37
#define USB_GET_INPUT			30
38
 
38
 
39
 
39
 
40
void usbEventResetReady(void);
40
void usbEventResetReady(void);
41
static void calibrateOscillator(void);
41
static void calibrateOscillator(void);
-
 
42
static void updateDecimals(uint8_t dis);
42
static void updateDisplay(uint8_t dis);
43
static void updateDisplay(uint8_t dis);
43
static void updateInput();
44
static void updateInput();
44
static void getDisplayVersion(uint8_t dis);
45
static void getDisplayVersion(uint8_t dis);
45
 
46
 
46
struct display_type {
47
struct display_type {
47
	uint8_t address;
48
	uint8_t address;
48
	uint8_t value[10];
49
	uint8_t value[10];
49
	uint16_t decpts;
50
	uint16_t decpts;
50
	uint16_t version;	// HB = HW, LB = SW
51
	uint16_t version;	// HB = HW, LB = SW
51
 
-
 
-
 
52
	// @TODO: Make refresh something to do with decpts
52
	uint8_t refresh;	// Decimal point refresh
53
	uint8_t refresh;	// Decimal point refresh
53
 
54
 
54
	int8_t rotary;		// State of the rotary encoder
55
	int8_t rotary;		// State of the rotary encoder
55
	uint8_t buttons;	// State of the buttons
56
	uint8_t buttons;	// State of the buttons
56
} display[DISPLAYS_ATTACHED];
57
} display[DISPLAYS_ATTACHED];
Line 126... Line 127...
126
    		latchDisplay = 255;
127
    		latchDisplay = 255;
127
    	}
128
    	}
128
 
129
 
129
    	for (i=0; i<DISPLAYS_ATTACHED; i++) {
130
    	for (i=0; i<DISPLAYS_ATTACHED; i++) {
130
    		if (display[i].refresh) {
131
    		if (display[i].refresh) {
131
    			i2cbb_Init();
132
    			updateDecimals(i);
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;
133
				display[i].refresh = 0;
139
    		}
134
    		}
140
 
135
 
141
    	}
136
    	}
142
 
137
 
Line 206... Line 201...
206
		i2cbb_Stop();
201
		i2cbb_Stop();
207
	}
202
	}
208
 
203
 
209
}
204
}
210
 
205
 
-
 
206
static void updateDecimals(uint8_t dis) {
-
 
207
	i2cbb_Init();
-
 
208
	i2cbb_Start();
-
 
209
	i2cbb_Write( display[dis].address << 1 );
-
 
210
	i2cbb_Write( I2C_SET_DECIMAL_PTS );
-
 
211
	i2cbb_Write((uint8_t)(display[dis].decpts>>8));
-
 
212
	i2cbb_Write((uint8_t)display[dis].decpts);
-
 
213
	i2cbb_Stop();
-
 
214
}
-
 
215
 
211
// The the display digit display buffer to the board
216
// The the display digit display buffer to the board
212
// We can select which display to update as this can
217
// We can select which display to update as this can
213
//  get slow if updates are being done all the time,
218
//  get slow if updates are being done all the time,
214
//  which might affect the user input data tasks
219
//  which might affect the user input data tasks
215
static void updateDisplay(uint8_t dis) {
220
static void updateDisplay(uint8_t dis) {
216
    cbi(PORTB, PB0);
-
 
217
 
-
 
218
    // Send the display buffer to display board
221
    // Send the display buffer to display board
219
    uint8_t update = 0;
222
    uint8_t update = 0;
220
    uint8_t n;
223
    uint8_t n;
221
    for (n=0; n<10; n++) {
224
    for (n=0; n<10; n++) {
222
    	if (rbi(display[dis].value[n], 7)) {
225
    	if (rbi(display[dis].value[n], 7)) {
Line 238... Line 241...
238
    		uint8_t send = (n << 4) | display[dis].value[n];
241
    		uint8_t send = (n << 4) | display[dis].value[n];
239
    		i2cbb_Write( send );
242
    		i2cbb_Write( send );
240
    	}
243
    	}
241
    }
244
    }
242
    i2cbb_Stop();
245
    i2cbb_Stop();
243
 
-
 
244
    sbi(PORTB, PB0);
-
 
245
}
246
}
246
 
247
 
247
// The USB functions to transmit/receive data from USB host.
248
// The USB functions to transmit/receive data from USB host.
248
usbMsgLen_t usbFunctionSetup(uchar data[8])
249
usbMsgLen_t usbFunctionSetup(uchar data[8])
249
{
250
{
Line 255... Line 256...
255
			latchDisplay = rq->wValue.bytes[0];;
256
			latchDisplay = rq->wValue.bytes[0];;
256
			break;
257
			break;
257
		}
258
		}
258
 
259
 
259
		case USB_SET_POINTS: {
260
		case USB_SET_POINTS: {
260
			display[0].decpts = rq->wValue.word;
261
			if (display[0].decpts != rq->wValue.word) {
-
 
262
				display[0].refresh = 1;
261
			display[1].decpts = rq->wIndex.word;
263
				display[0].decpts = rq->wValue.word;
-
 
264
			}
262
 
265
 
-
 
266
			if (display[1].decpts != rq->wIndex.word) {
263
			display[0].refresh = 1;
267
				display[1].refresh = 1;
264
			display[1].refresh = 1;
268
				display[1].decpts = rq->wIndex.word;
-
 
269
			}
265
		}
270
		}
266
 
271
 
267
		// Sets the display boards digit buffer. Only on display
272
		// Sets the display boards digit buffer. Only on display
268
		//  board is updated per request. Also does decimal points
273
		//  board is updated per request. Also does decimal points
269
		case USB_SET_DISPLAY1: {
274
		case USB_SET_DISPLAY1: {