Subversion Repositories group.electronics

Rev

Rev 136 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 136 Rev 137
Line 17... Line 17...
17
#endif
17
#endif
18
 
18
 
19
static void calibrateOscillator(void);
19
static void calibrateOscillator(void);
20
void usbEventResetReady(void);
20
void usbEventResetReady(void);
21
 
21
 
22
static void updateDisplays();
22
//static void updateDisplays();
-
 
23
static void updateDisplay(uint8_t dis);
23
 
24
 
24
#define DIS_COM_ACTIVE
25
#define DIS_COM_ACTIVE
25
#define DIS_COM_STANDBY
26
#define DIS_COM_STANDBY
26
#define DIS_NAV_ACTIVE
27
#define DIS_NAV_ACTIVE
27
#define DIS_NAV_STANDBY
28
#define DIS_NAV_STANDBY
28
 
29
 
29
// Hold the chars for the display panels
30
// Hold the chars for the display panels
30
 
31
 
31
volatile uint8_t displays[5][6] = {
32
volatile uint8_t displays[5][6] = {
32
							{ 0, 0, 0, 0, 0},	// DIS_COM_ACTIVE
33
							{ 6, 6, 6, 6, 6},	// DIS_COM_ACTIVE
33
							{ 0, 0, 0, 0, 0},	// DIS_COM_STANDBY
34
							{ 7, 7, 7, 7, 7},	// DIS_COM_STANDBY
34
							{ 0, 0, 0, 0, 0},	// DIS_NAV_ACTIVE
35
							{ 0, 0, 0, 0, 0},	// DIS_NAV_ACTIVE
35
							{ 0, 0, 0, 0, 0},	// DIS_NAV_STANDBY
36
							{ 0, 0, 0, 0, 0},	// DIS_NAV_STANDBY
36
						 };
37
						 };
37
 
38
 
38
 
39
 
39
//static uchar usbReplyBuf[16];
40
//static uchar usbReplyBuf[16];
40
volatile static uint8_t bytesRemaining;
41
volatile static uint8_t bytesRemaining;
41
volatile static uint8_t* writeIdx;
42
//volatile static uint8_t* writeIdx;
42
 
43
 
43
volatile uint8_t tmr0_ovf = 0;
44
volatile uint8_t tmr0_ovf = 0;
44
volatile uint8_t update = 1;
45
volatile uint8_t update = 255;
45
 
46
 
46
 
47
 
47
 
48
 
48
int main(void) {
49
int main(void) {
49
	uchar   calibrationValue;
50
	uchar   calibrationValue;
Line 66... Line 67...
66
		PB5	-
67
		PB5	-
67
	*/
68
	*/
68
	DDRB          = 0B00000001;
69
	DDRB          = 0B00000001;
69
	PORTB         = 0B00000001;
70
	PORTB         = 0B00000001;
70
 
71
 
-
 
72
 
71
    usbDeviceDisconnect();
73
    usbDeviceDisconnect();
72
    _delay_ms(300);
74
    _delay_ms(500);
73
    usbDeviceConnect();
75
    usbDeviceConnect();
74
 
76
 
75
    systime = 0;
77
    systime = 0;
76
    sysclockInit();
78
    sysclockInit();
77
 
79
 
Line 89... Line 91...
89
    i2cbb_Write(0x08);
91
    i2cbb_Write(0x08);
90
    i2cbb_Stop();
92
    i2cbb_Stop();
91
    sbi(PORTB, PB0);
93
    sbi(PORTB, PB0);
92
*/
94
*/
93
 
95
 
-
 
96
    uint8_t i;
-
 
97
    for (i=0; i<2; i++)
-
 
98
    	updateDisplay(i);
-
 
99
 
-
 
100
 
94
    for(;;){
101
    for(;;){
95
    	 wdt_reset();
102
    	 wdt_reset();
96
    	 usbPoll();
103
    	 usbPoll();
97
 
104
 
98
    	if (update) {
105
    	if (update != 255) {
99
    		updateDisplays();
106
    		updateDisplay(update);
-
 
107
    		update = 255;
100
    	}
108
    	}
101
 
109
 
102
    }
110
    }
103
    return 0;
111
    return 0;
104
}
112
}
105
 
113
 
-
 
114
static void updateDisplay(uint8_t dis) {
-
 
115
    cbi(PORTB, PB0);
-
 
116
    i2cbb_Init();
-
 
117
    i2cbb_Start();
-
 
118
    i2cbb_Write(0x4c);
-
 
119
    i2cbb_Write(0x05);
-
 
120
    uint8_t n;
-
 
121
    for (n=0; n<5; n++) {
-
 
122
    	i2cbb_Write( ((n+5*dis)<<4) | (displays[dis][n] & 0x0f) );
-
 
123
    }
-
 
124
    i2cbb_Stop();
-
 
125
    sbi(PORTB, PB0);
-
 
126
}
-
 
127
 
-
 
128
/*
106
static void updateDisplays() {
129
static void updateDisplays() {
107
    cbi(PORTB, PB0);
130
    cbi(PORTB, PB0);
108
    i2cbb_Init();
131
    i2cbb_Init();
109
    i2cbb_Start();
132
    i2cbb_Start();
110
    i2cbb_Write(0x4c);
133
    i2cbb_Write(0x4c);
Line 132... Line 155...
132
    sbi(PORTB, PB0);
155
    sbi(PORTB, PB0);
133
 
156
 
134
 
157
 
135
	update = 0;
158
	update = 0;
136
}
159
}
-
 
160
*/
137
 
161
 
138
static void calibrateOscillator(void) {
162
static void calibrateOscillator(void) {
139
    uchar step = 128;
163
    uchar step = 128;
140
    uchar trialValue = 0, optimumValue;
164
    uchar trialValue = 0, optimumValue;
141
    int x, optimumDev;
165
    int x, optimumDev;
Line 167... Line 191...
167
 
191
 
168
#define USB_GET_CONT_VER		10		// Send the controller version data
192
#define USB_GET_CONT_VER		10		// Send the controller version data
169
#define USB_GET_COMM_VER		11		// Send the comm display version data
193
#define USB_GET_COMM_VER		11		// Send the comm display version data
170
#define USB_GET_NAV_VER			12		// Send the nav display version data
194
#define USB_GET_NAV_VER			12		// Send the nav display version data
171
 
195
 
172
#define USB_SET_COMM_ACTIVE 	20		// Set the comm active freq
-
 
173
#define USB_SET_COMM_STANDBY	21		// Set the comm standby freq
-
 
174
#define USB_SET_NAV_ACTIVE		22		// Set the nav active freq
-
 
175
#define USB_SET_NAV_STANDBY		23		// Set the nav standby freq
-
 
176
#define USB_BLANK_ALL			24		// Blank all displays
-
 
177
#define USB_SET_ALL				25		// Blank all displays
196
#define USB_SET_DIGIT			20		// Set a digit on display
178
 
197
 
179
#define USB_GET_COMM_ENC		30		// Send the comm rotary encoder position
198
#define USB_GET_COMM_ENC		30		// Send the comm rotary encoder position
180
#define USB_RESET_COMM_ENC		31		// Reset the comm encoder to 0
199
#define USB_RESET_COMM_ENC		31		// Reset the comm encoder to 0
181
#define USB_GET_NAV_ENC			32		// Send the nav rotary encoder position
200
#define USB_GET_NAV_ENC			32		// Send the nav rotary encoder position
182
#define USB_RESET_NAV_ENC		33		// Reset the nav encoder to 0
201
#define USB_RESET_NAV_ENC		33		// Reset the nav encoder to 0
Line 189... Line 208...
189
{
208
{
190
    usbRequest_t    *rq = (void *)data;
209
    usbRequest_t    *rq = (void *)data;
191
 
210
 
192
 
211
 
193
	switch (rq->bRequest ) {
212
	switch (rq->bRequest ) {
194
	case 20: {
213
		case USB_SET_DIGIT: {
195
		uint8_t dis = rq->wValue.bytes[0];
214
			uint8_t dis = rq->wValue.bytes[1];
196
		uint8_t dig = rq->wValue.bytes[1];
215
			uint8_t dig = rq->wValue.bytes[0];
197
		uint8_t val = rq->wIndex.bytes[0];
216
			uint8_t val = rq->wIndex.bytes[0];
198
		displays[dis][dig] = val;
217
			displays[dis][dig] = val;
199
		update = 1;
218
			update = dis;
200
		break;
219
			break;
201
		}
220
		}
202
 
221
 
203
	}
222
	}
204
	return 0;
223
	return 0;
205
}
224
}