QlightRead Project
|
00001 00038 #include "at90usbxx2_driver.h" 00039 00047 USB_ClassInfo_CDC_Device_t PAMO_CDC_Interface = { 00048 .Config = 00049 { 00050 .ControlInterfaceNumber = 0, 00051 00052 .DataINEndpointNumber = DATAINEP, 00053 .DataINEndpointSize = DATAINSIZE, 00054 .DataINEndpointDoubleBank = false, 00055 00056 .DataOUTEndpointNumber = DATAOUTEP, 00057 .DataOUTEndpointSize = DATAOUTSIZE, 00058 .DataOUTEndpointDoubleBank = false, 00059 00060 }, 00061 }; 00062 00071 void USB_re_fresh(void) { 00072 usb_control(); 00073 _delay_ms(20); 00074 } 00075 00086 SINT8 SPI_init(void) { 00087 00088 /* Set pin PB0 (SS), PB1 (SCLK) to Output */ 00089 DDRB = (1<<DDB0) | (1<<DDB1); 00090 00091 /* Enable SPI Module */ 00092 PRR0 &= ~(1<<PRSPI); 00093 00094 /* Enable Spi, set SPI as Master, set frequenzy prescaler 1/128 */ 00095 SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (1<<SPR0); 00096 00097 return 0; 00098 } 00099 00111 SINT8 uC_init(void) { 00112 00113 DDRB = 0xFF; // PORTB auf output setzen 00114 PORTB = 0xFF; 00115 CKSEL0 = 0x05; //set external oscillator (16Mhz) 00116 CKSEL1 = 0x0E; 00117 CLKPR = 0x80; //set prescaler to 1 00118 CLKPR = 0x00; 00119 return 0; 00120 } 00121 00132 SINT8 USART_init(void) { 00133 00134 /* set wordwidth 00135 8 data, 2 stop bits 00136 */ 00137 UCSR1C = (1<<USBS1)|(3<<UCSZ10); 00138 00139 /* enable Transmitter */ 00140 UCSR1B |= (1<<TXEN1); 00141 00142 /* enable Interrupt on Transmit Complete */ 00143 UCSR1B |= (1<<TXCIE1); 00144 00145 /* set baudrate */ 00146 UBRR1H = (unsigned char) (BRATE>>8); 00147 UBRR1L = (unsigned char) BRATE; 00148 00149 return 0; 00150 } 00151 00162 SINT8 SPIclkenable(void){ 00163 SPDR = 0; 00164 while(!(SPSR & (1<<SPIF))); 00165 return 0; 00166 } 00167 00178 UINT8 getSPIvalue(void) { 00179 while(!(SPSR & (1<<SPIF))); 00180 return SPDR; 00181 } 00182 00193 void SET_CS(void) { 00194 PORTB &= ~(1<<PB0); 00195 } 00196 00207 void _SET_CS(void) { 00208 PORTB |= (1<<PB0); 00209 } 00210 00221 SINT8 USB_init(void) { 00222 /* Disable clock division */ 00223 clock_prescale_set(clock_div_1); 00224 00225 /* Hardware Initialization */ 00226 USB_Init(); 00227 return 0; 00228 } 00229 00240 void EVENT_USB_Device_Connect(void) { 00241 PORTB &= ~(1<<PB6); 00242 } 00243 00254 void EVENT_USB_Device_Disconnect(void) { 00255 PORTB |= (1<<PB6); 00256 } 00257 00268 void EVENT_USB_Device_ConfigurationChanged(void) { 00269 bool ConfigSuccess = true; 00270 ConfigSuccess &= CDC_Device_ConfigureEndpoints(&PAMO_CDC_Interface); 00271 } 00272 00283 void EVENT_USB_Device_ControlRequest(void) { 00284 CDC_Device_ProcessControlRequest(&PAMO_CDC_Interface); 00285 } 00286 00297 void usb_control(void) { 00298 00299 CDC_Device_USBTask(&PAMO_CDC_Interface); 00300 USB_USBTask(); 00301 00302 } 00303 00314 SINT8 write_EndPoint(UINT16 value) { 00315 00316 Endpoint_SelectEndpoint(DATAINEP); 00317 char buf[16]; 00318 sprintf(buf,"%d",value); 00319 /* Write the String to the Endpoint */ 00320 Endpoint_Write_Stream_LE(buf, DATAINSIZE , NULL); 00321 /* Finalize the stream transfer to send the last packet */ 00322 Endpoint_ClearIN(); 00323 00324 return 0; 00325 }