Rev 3325 Rev 3326
Line 100... Line 100...
100   100  
101 void main() 101 void main()
102 { 102 {
103   103  
104 unsigned int8 replyBuf[4]; 104 unsigned int8 replyBuf[4];
-   105 unsigned int8 i=0;
105   106  
106 setup_adc_ports(NO_ANALOGS|VSS_VDD); 107 setup_adc_ports(NO_ANALOGS|VSS_VDD);
107 setup_adc(ADC_CLOCK_DIV_2); 108 setup_adc(ADC_CLOCK_DIV_2);
108 setup_psp(PSP_DISABLED); 109 setup_psp(PSP_DISABLED);
109 setup_wdt(WDT_OFF); 110 setup_wdt(WDT_OFF);
Line 113... Line 114...
113 setup_timer_3(T3_DISABLED|T3_DIV_BY_1); 114 setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
114 setup_ccp1(CCP_OFF); 115 setup_ccp1(CCP_OFF);
115 setup_comparator(NC_NC_NC_NC); 116 setup_comparator(NC_NC_NC_NC);
116 setup_vref(FALSE); 117 setup_vref(FALSE);
117   118  
118 usb_init(); 119 printf("MLAB I2C to USB adapter started \n\r ");
119   120  
-   121 output_high(PIN_B4);
120   122  
-   123 usb_init();
121   124  
122 while (TRUE) { 125 while (TRUE) {
123 if (usb_enumerated()) 126 if (usb_enumerated())
124 { 127 {
125 usb_gets(0,control_data,8,100); -  
126   128  
-   129 output_low(PIN_B4);
-   130  
127 switch(control_data[1]) 131 /* if(usb_kbhit(0))
128 { 132 {
-   133 printf("control data received... \n\r");
-   134
-   135 usb_gets(0,control_data,8,100);
-   136
-   137 switch(control_data[1])
-   138 {
129 case CMD_ECHO: // echo (for transfer reliability testing) 139 case CMD_ECHO: // echo (for transfer reliability testing)
130 replyBuf[0] = control_data[2]; 140 replyBuf[0] = control_data[2];
131 replyBuf[1] = control_data[3]; 141 replyBuf[1] = control_data[3];
132 usb_puts(0,replyBuf,2,50); 142 usb_puts(0,replyBuf,2,50);
133 break; 143 break;
134 144
135 case CMD_GET_FUNC: 145 case CMD_GET_FUNC:
136 usb_puts(0,(I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL),32,50); 146 usb_puts(0,(I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL),32,50);
137 break; 147 break;
138 148
139 case CMD_SET_DELAY: 149 case CMD_SET_DELAY:
140 /* The delay function used delays 4 system ticks per cycle. */ -  
141 /* This gives 1/3us at 12Mhz per cycle. The delay function is */ -  
142 /* called twice per clock edge and thus four times per full cycle. */ -  
143 /* Thus it is called one time per edge with the full delay */ -  
144 /* value and one time with the half one. Resulting in */ -  
145 /* 2 * n * 1/3 + 2 * 1/2 n * 1/3 = n us. */ -  
146 clock_delay = *(unsigned short*)(control_data+2); 150 clock_delay = *(unsigned short*)(control_data+2);
147 if(!clock_delay) clock_delay = 1; 151 if(!clock_delay) clock_delay = 1;
148 clock_delay2 = clock_delay/2; 152 clock_delay2 = clock_delay/2;
149 if(!clock_delay2) clock_delay2 = 1; 153 if(!clock_delay2) clock_delay2 = 1;
150 break; 154 break;
151 155
152 case CMD_I2C_IO: 156 case CMD_I2C_IO:
153 case CMD_I2C_IO + CMD_I2C_BEGIN: 157 case CMD_I2C_IO + CMD_I2C_BEGIN:
154 case CMD_I2C_IO + CMD_I2C_END: 158 case CMD_I2C_IO + CMD_I2C_END:
155 case CMD_I2C_IO + CMD_I2C_BEGIN + CMD_I2C_END: 159 case CMD_I2C_IO + CMD_I2C_BEGIN + CMD_I2C_END:
156 // these are only allowed as class transfers 160 // these are only allowed as class transfers
157 161
158 // return i2c_do((struct i2c_cmd*)data); 162 return i2c_do((struct i2c_cmd*)data);
159 break; 163 break;
160 164
161 case CMD_GET_STATUS: 165 case CMD_GET_STATUS:
162 replyBuf[0] = status; 166 replyBuf[0] = status;
163 usb_puts(0,replyBuf,1,50); 167 usb_puts(0,replyBuf,1,50);
164 break; 168 break;
165 169
166 default: 170 default:
167 // must not happen ... 171 // must not happen ...
168 break; 172 break;
-   173 }
-   174 }*/
-   175  
-   176 if(usb_kbhit(i))
-   177 {
-   178 printf(" data received at endpoint %d \n\r ", i);
169 } 179 }
170   180  
171 delay_ms(10); 181 delay_ms(10);
-   182  
-   183 output_high(PIN_B4);
-   184 i++;
172 } 185 }
173 } 186 }
174 } 187 }