First implementation of the USB communication.
This commit is contained in:
parent
9a8082065a
commit
09f600f9e1
4 changed files with 44 additions and 45 deletions
|
@ -16,7 +16,7 @@ int main(void)
|
|||
init();
|
||||
init_usb();
|
||||
|
||||
uint8_t anim = 0;
|
||||
//uint8_t anim = 0;
|
||||
|
||||
// Hauptschleife
|
||||
//while (1)
|
||||
|
@ -28,9 +28,9 @@ int main(void)
|
|||
// hier pause einfügen
|
||||
_delay_ms(50); // beispielsweise 50 ms => muss angepasst werden an usb kommunikation
|
||||
|
||||
anim++;
|
||||
/*anim++;
|
||||
|
||||
if (anim == 40)
|
||||
if (anim >= 0)
|
||||
{
|
||||
if (cube == 0xffffffff)
|
||||
cube = 0x07007007;
|
||||
|
@ -38,8 +38,18 @@ int main(void)
|
|||
cube = 0x00000000;
|
||||
else if (cube == 0x00000000)
|
||||
cube = 0xffffffff;
|
||||
anim = 0;
|
||||
}
|
||||
|
||||
anim = 0;
|
||||
}*/
|
||||
/*if (anim >= 40)
|
||||
{
|
||||
cube += 1;
|
||||
|
||||
if (cube > 0x07ffffff)
|
||||
cube = 0;
|
||||
|
||||
anim = 0;
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +68,7 @@ void init()
|
|||
//cli(); //
|
||||
|
||||
set_bit(TIMSK, OCIE1A); // Interrupt für ISR COMPA
|
||||
set_bit(TCCR1B, WGM12); // Überlauf
|
||||
//set_bit(TCCR1B, WGM12); // Überlauf
|
||||
|
||||
// Animations-Geschwindigkeit
|
||||
// (vergleichswert bei dem der Interrupt ausgelöst wird)
|
||||
|
@ -68,11 +78,10 @@ void init()
|
|||
|
||||
// anpassen auf reihenweise ausgabe
|
||||
// Vorteiler durch 64 (0x011) ----> CS12=0, CS11=1, CS10=1
|
||||
clear_bit(TCCR1B, CS12); // Prescaler 64
|
||||
set_bit(TCCR1B, CS11);
|
||||
set_bit(TCCR1B, CS10);
|
||||
|
||||
|
||||
//clear_bit(TCCR1B, CS12); // Prescaler 64
|
||||
//set_bit(TCCR1B, CS11);
|
||||
//set_bit(TCCR1B, CS10);
|
||||
TCCR1B |= (1 << CS11) | (1 << CS10) | (1 << WGM12);
|
||||
|
||||
sei(); // Set enable interrupt bit (Muss gesetzt werden damit es überhaupt aufgerufen wird)
|
||||
}
|
||||
|
@ -81,12 +90,12 @@ void init()
|
|||
//SIGNAL(SIG_OUTPUT_COMPARE1A) // alte schreibweise
|
||||
ISR (TIMER1_COMPA_vect)
|
||||
{
|
||||
// PORTD = __, 9, C, B, A,D+,D-,__
|
||||
|
||||
// PORTD = __, 9, C, B, A,D+,D-,__
|
||||
PORTD &= 0b10000111; // 7tes Bit löschen (Leitung 9) und alle Ebenen deaktivieren
|
||||
PORTD |= ((1 << cube_level) << 3); // cube_level setzen (Ebene A=0, B=1, C=2)
|
||||
|
||||
uint32_t tmp = cube_level * 9;
|
||||
uint32_t tmp1 = tmp + 8;
|
||||
|
||||
// PORTB = 1..8
|
||||
// 0 = leuchtet, 1 = leuchtet nicht (invertiert!)
|
||||
|
@ -101,9 +110,11 @@ ISR (TIMER1_COMPA_vect)
|
|||
PORTD &= ~(1 << 6);
|
||||
else
|
||||
PORTD |= (1 << 6);
|
||||
|
||||
//PORTD |= (1 << 6); // test to always off
|
||||
|
||||
cube_level++;
|
||||
if (cube_level > 2) cube_level = 0;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
//#include <avr/pgmspace.h>
|
||||
//#include <avr/wdt.h>
|
||||
|
||||
// Cube-Data
|
||||
//volatile uint32_t cube = 0x07007007; // Aktuelles Frame
|
||||
|
@ -28,7 +26,6 @@ volatile uint8_t cube_level = 0; // Ebene
|
|||
|
||||
// Prototypen
|
||||
void init(void);
|
||||
void loop(uint8_t);
|
||||
|
||||
extern void init_usb(void);
|
||||
extern void usbPoll(void);
|
||||
|
|
|
@ -19,29 +19,25 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||
if ( rq->bRequest == CUSTOM_RQ_SET_STATUS )
|
||||
{
|
||||
|
||||
/*
|
||||
if (rq->wIndex.bytes[0] == 0)
|
||||
cube[0][0][0] = 1;
|
||||
if (rq->wIndex.bytes[0] == 1)
|
||||
cube[0][0][1] = 1;
|
||||
if (rq->wIndex.bytes[0] == 2)
|
||||
cube[0][0][2] = 1;
|
||||
if (rq->wIndex.bytes[0] == 3)
|
||||
cube[0][1][0] = 1;
|
||||
if ( rq->wIndex.bytes[0] == 27 )
|
||||
{
|
||||
cube = (cube & (uint32_t)0xffff0000) |
|
||||
rq->wValue.bytes[0] +
|
||||
(rq->wValue.bytes[1] << 8);
|
||||
} else if ( rq->wIndex.bytes[0] == 28 )
|
||||
{
|
||||
cube = (cube & (uint32_t)0x0000ffff) |
|
||||
((uint32_t)(rq->wValue.bytes[0] +
|
||||
(rq->wValue.bytes[1] << 8)) << 16);
|
||||
} else if ( rq->wIndex.bytes[0] < 27 )
|
||||
{
|
||||
if ( rq->wValue.bytes[0] == 1 )
|
||||
cube |= ((uint32_t)1 << rq->wIndex.bytes[0]);
|
||||
else
|
||||
cube &= ~((uint32_t)1 << rq->wIndex.bytes[0]);
|
||||
}
|
||||
|
||||
if (rq->wIndex.bytes[0] == 0)
|
||||
x = rq->wValue.bytes[0];
|
||||
|
||||
else if (rq->wIndex.bytes[0] == 1)
|
||||
y = rq->wValue.bytes[0];
|
||||
|
||||
else if (rq->wIndex.bytes[0] == 2)
|
||||
z = rq->wValue.bytes[0];
|
||||
|
||||
else if (rq->wIndex.bytes[0] == 3)
|
||||
//cube[x][y][z] = rq->wValue.bytes[0];
|
||||
|
||||
} else if ( rq->bRequest == CUSTOM_RQ_GET_STATUS ) {
|
||||
//} else if ( rq->bRequest == CUSTOM_RQ_GET_STATUS ) {
|
||||
// Send one byte to the USB host.
|
||||
|
||||
//static uchar dataBuffer[1]; // buffer must stay valid when usbFunctionSetup returns
|
||||
|
@ -49,9 +45,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
|
|||
//return 1; // tell the driver to send 1 byte
|
||||
|
||||
//return 0; // tell the driver to send 0 byte
|
||||
*/
|
||||
}
|
||||
}else{
|
||||
//} else {
|
||||
/* class requests USBRQ_HID_GET_REPORT and USBRQ_HID_SET_REPORT are
|
||||
* not implemented since we never call them. The operating system
|
||||
* won't call them either because our descriptor defines no meaning.
|
||||
|
|
|
@ -55,14 +55,10 @@ PROGMEM char usbHidReportDescriptor[22] = { /* USB report descriptor */
|
|||
|
||||
void init_usb(void);
|
||||
|
||||
/*volatile uint8_t x;
|
||||
volatile uint8_t y;
|
||||
volatile uint8_t z;*/
|
||||
|
||||
// usb buffer
|
||||
//extern uint8_t buffer[3][3][3]; // Framebuffer
|
||||
//extern uint8_t cube[3][3][3]; // Framebuffer
|
||||
extern uint32_t cube; // Framebuffer
|
||||
extern volatile uint32_t cube; // Framebuffer
|
||||
|
||||
#endif // __usb_h__
|
||||
|
||||
|
|
Loading…
Reference in a new issue