Merge branch 'klaute' into USB
Conflicts: firmware/main.c firmware/main.h firmware/usb.c firmware/usb.h
This commit is contained in:
commit
fa69c53f89
9 changed files with 216 additions and 116 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -8,3 +8,7 @@ firmware/.dep
|
|||
*.lss
|
||||
*.s#*
|
||||
*.b#*
|
||||
*.eep
|
||||
*.map
|
||||
*.sym
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ usb_dev_handle *handle = NULL;
|
|||
const unsigned char rawVid[2] = {USB_CFG_VENDOR_ID}, rawPid[2] = {USB_CFG_DEVICE_ID};
|
||||
char vendor[] = {USB_CFG_VENDOR_NAME, 0}, product[] = {USB_CFG_DEVICE_NAME, 0};
|
||||
char buffer[4];
|
||||
int cnt, vid, pid;
|
||||
int vid, pid;
|
||||
|
||||
usb_init();
|
||||
|
||||
|
@ -67,43 +67,28 @@ int cnt, vid, pid;
|
|||
}
|
||||
#endif
|
||||
|
||||
int i,x,y,z,onoff = 0;
|
||||
while (1)
|
||||
// int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout);
|
||||
// 32 bit in 2 transmission
|
||||
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0x7007, 0x1B, buffer, 0, 300);
|
||||
//sleep(2);
|
||||
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0x0700, 0x1C, buffer, 0, 300);
|
||||
|
||||
// bitwise set/get
|
||||
//usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0, 25, buffer, 0, 5000);
|
||||
sleep(5);
|
||||
|
||||
int i = 0;
|
||||
for (i = 0; i < 27; i++)
|
||||
{
|
||||
onoff = (onoff == 0) ? 1 : 0;
|
||||
for (x = 0; x <3; x++)
|
||||
for (y = 0; y <3; y++)
|
||||
for (z = 0; z <3; z++)
|
||||
{
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
int v = 0;
|
||||
if (i == 0)
|
||||
v = x;
|
||||
if (i == 1)
|
||||
v = y;
|
||||
if (i == 2)
|
||||
v = z;
|
||||
if (i == 3)
|
||||
v = onoff;
|
||||
cnt = -1;
|
||||
do {
|
||||
sleep(1);
|
||||
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, v, 0, buffer, 0, 5000);
|
||||
if (cnt < 0)
|
||||
{
|
||||
if(usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0){
|
||||
fprintf(stderr, "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid, pid);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
} while (cnt < 0);
|
||||
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 1, i, buffer, 0, 300);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fprintf(stdout, "%d %d %d %d\n",x,y,z,onoff);
|
||||
}
|
||||
}
|
||||
for (i = 26; i >= 0; i--)
|
||||
{
|
||||
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0, i, buffer, 0, 300);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
usb_close(handle);
|
||||
return 0;
|
||||
|
|
59
doc/lsusb.txt
Normal file
59
doc/lsusb.txt
Normal file
|
@ -0,0 +1,59 @@
|
|||
|
||||
Bus 002 Device 013: ID 16c0:05df VOTI
|
||||
Device Descriptor:
|
||||
bLength 18
|
||||
bDescriptorType 1
|
||||
bcdUSB 1.10
|
||||
bDeviceClass 0 (Defined at Interface level)
|
||||
bDeviceSubClass 0
|
||||
bDeviceProtocol 0
|
||||
bMaxPacketSize0 8
|
||||
idVendor 0x16c0 VOTI
|
||||
idProduct 0x05df
|
||||
bcdDevice 1.00
|
||||
iManufacturer 1 CTHN.de
|
||||
iProduct 2 MiniLEDCube
|
||||
iSerial 0
|
||||
bNumConfigurations 1
|
||||
Configuration Descriptor:
|
||||
bLength 9
|
||||
bDescriptorType 2
|
||||
wTotalLength 34
|
||||
bNumInterfaces 1
|
||||
bConfigurationValue 1
|
||||
iConfiguration 0
|
||||
bmAttributes 0x80
|
||||
(Bus Powered)
|
||||
MaxPower 250mA
|
||||
Interface Descriptor:
|
||||
bLength 9
|
||||
bDescriptorType 4
|
||||
bInterfaceNumber 0
|
||||
bAlternateSetting 0
|
||||
bNumEndpoints 1
|
||||
bInterfaceClass 3 Human Interface Device
|
||||
bInterfaceSubClass 0 No Subclass
|
||||
bInterfaceProtocol 0 None
|
||||
iInterface 0
|
||||
HID Device Descriptor:
|
||||
bLength 9
|
||||
bDescriptorType 33
|
||||
bcdHID 1.01
|
||||
bCountryCode 0 Not supported
|
||||
bNumDescriptors 1
|
||||
bDescriptorType 34 Report
|
||||
wDescriptorLength 22
|
||||
Report Descriptors:
|
||||
** UNAVAILABLE **
|
||||
Endpoint Descriptor:
|
||||
bLength 7
|
||||
bDescriptorType 5
|
||||
bEndpointAddress 0x81 EP 1 IN
|
||||
bmAttributes 3
|
||||
Transfer Type Interrupt
|
||||
Synch Type None
|
||||
Usage Type Data
|
||||
wMaxPacketSize 0x0008 1x 8 bytes
|
||||
bInterval 10
|
||||
Device Status: 0x0000
|
||||
(Bus Powered)
|
|
@ -1,37 +1,8 @@
|
|||
#define F_CPU 12000000UL
|
||||
|
||||
// Bitpopelei
|
||||
// Bitshifting
|
||||
#define set_bit(var, bit) ((var) |= (1 << (bit)))
|
||||
#define clear_bit(var, bit) ((var) &= (unsigned)~(1 << (bit)))
|
||||
|
||||
// Bool
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
// Definitionen
|
||||
#define PIXEL_TON 30
|
||||
#define PIXEL_TOFF 10
|
||||
|
||||
#define sleep_nop(cnt) for (uint8_t i = 0; i < cnt; i++) { asm volatile("nop"::); }
|
||||
|
||||
// Pixelmakros
|
||||
#define PSET(x,y,z) (0b01000000 | ((z * 3 + x) + y * 9))
|
||||
#define PCLEAR(x,y,z) (0b00000000 | ((z * 3 + x) + y * 9))
|
||||
|
||||
// Instructions
|
||||
#define CLEAR 0b10000000
|
||||
#define SET 0b10010000
|
||||
#define FPS 0b10110000
|
||||
#define NEXT 0b11110000
|
||||
|
||||
// Variablen
|
||||
#define VAR_FPS 0
|
||||
|
||||
// Für CLEAR und SET
|
||||
#define CLEAR_ALL 0
|
||||
#define SET_ALL 0
|
||||
|
||||
// Für NEXT
|
||||
#define JUMP_FORWARD 1
|
||||
#define JUMP_BACKWARD 2
|
||||
|
||||
|
|
52
firmware/isr_test.c
Normal file
52
firmware/isr_test.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int PORTD = 0xff;
|
||||
int PORTB = 0xff;
|
||||
int cube = 0x000001ff;
|
||||
int cube_level = 0;
|
||||
|
||||
char test[100];
|
||||
|
||||
int i = 0;
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
|
||||
printf("-----------------\ncube_level = %d\n",cube_level);
|
||||
|
||||
printf("PORTD = 0x%2x\n", PORTD);
|
||||
printf("PORTB = 0x%2x\n", PORTB);
|
||||
|
||||
PORTD &= 0x87; // 0x87 = 0b10000111; // 7tes Bit löschen (Leitung 9) und alle Ebenen deaktivieren
|
||||
|
||||
printf("& 0b10000111: PORTD = 0x%2x\n", PORTD);
|
||||
|
||||
PORTD |= ((1 << cube_level)<< 3); // cube_level setzen (Ebene A=0, B=1, C=2)
|
||||
|
||||
printf("Level festlegen: PORTD = 0x%2x\n", PORTD);
|
||||
|
||||
int tmp = cube_level * 9;
|
||||
|
||||
printf("8 Bits aus cube: PORTD = 0x%2x\n", ((~cube & (0xff << tmp)) >> tmp));
|
||||
// PORTB = 1..8
|
||||
// 0 = leuchtet, 1 = leuchtet nicht (invertiert!)
|
||||
PORTB = ((~cube & (0xff << tmp)) >> tmp);
|
||||
|
||||
printf("Pins1-8: PORTB = 0x%2x\n", PORTB);
|
||||
|
||||
// PORTD &= 0b10111111; // bereits oben erledigt
|
||||
PORTD |= (((~cube & (1 << (tmp+8))) >> (tmp+8)) << 6);
|
||||
|
||||
printf("Pin9: PORTD = 0x%2x\n", PORTD);
|
||||
|
||||
cube_level++;
|
||||
if (cube_level > 2) cube_level = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -16,6 +16,8 @@ int main(void)
|
|||
init();
|
||||
init_usb();
|
||||
|
||||
//uint8_t anim = 0;
|
||||
|
||||
// Hauptschleife
|
||||
//while (1)
|
||||
for (;;)
|
||||
|
@ -24,7 +26,30 @@ int main(void)
|
|||
usbPoll(); // keep connected
|
||||
|
||||
// hier pause einfügen
|
||||
_delay_ms(50); // beispielsweise 50 ms => muss angepasst werden an usb kommunikation
|
||||
//_delay_ms(1); // beispielsweise 50 ms => muss angepasst werden an usb kommunikation
|
||||
|
||||
/*anim++;
|
||||
|
||||
if (anim >= 0)
|
||||
{
|
||||
if (cube == 0xffffffff)
|
||||
cube = 0x07007007;
|
||||
else if (cube == 0x07007007)
|
||||
cube = 0x00000000;
|
||||
else if (cube == 0x00000000)
|
||||
cube = 0xffffffff;
|
||||
|
||||
anim = 0;
|
||||
}*/
|
||||
/*if (anim >= 40)
|
||||
{
|
||||
cube += 1;
|
||||
|
||||
if (cube > 0x07ffffff)
|
||||
cube = 0;
|
||||
|
||||
anim = 0;
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -36,14 +61,14 @@ void init()
|
|||
DDRB = 0b11111111; // PB0-PB7: LED 1-8 (Kathoden)
|
||||
PORTB = 0b11111111; // HIGH
|
||||
|
||||
DDRD = 0b1111000; // PD6: LED 9 (Kathode); PD5-PD3: A-C (Anoden)
|
||||
PORTD = 0b1000000;
|
||||
DDRD = 0b01111000; // PD6: LED 9 (Kathode); PD5-PD3: A-C (Anoden)
|
||||
PORTD = 0b01000000;
|
||||
|
||||
// Timer-Interrupt "TIMER1" vorbereiten
|
||||
//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)
|
||||
|
@ -53,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)
|
||||
}
|
||||
|
@ -66,18 +90,31 @@ void init()
|
|||
//SIGNAL(SIG_OUTPUT_COMPARE1A) // alte schreibweise
|
||||
ISR (TIMER1_COMPA_vect)
|
||||
{
|
||||
// PORTD = __, 9, C, B, A,D+,D-,__
|
||||
PORTD &= 0b11000111; // Reset durch Bitmaske
|
||||
PORTD |= ((1 << (cube_level))<< 3); // Level setzen (A=0, B=1, C=2)
|
||||
|
||||
// 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;
|
||||
|
||||
// PORTB = 1..8
|
||||
// 0 = leuchtet, 1 = leuchtet nicht (invertiert!)
|
||||
PORTB = ~(cube & (0b11111111 << (cube_level*9)));
|
||||
//PORTB = ~((uint32_t)(cube & (0b11111111 << tmp)) >> tmp);
|
||||
//PORTB = ((uint32_t)(~cube & (uint32_t)(0xff << tmp)) >> tmp);
|
||||
PORTB = ~((cube >> tmp) & 0xff);
|
||||
|
||||
PORTD &= 0b10111111; // 7tes Bit löschen (9)
|
||||
PORTD |= ~((cube & (1 << (cube_level*9+8))) << 6);
|
||||
// PORTD &= 0b10111111; // bereits oben erledigt
|
||||
//PORTD |= ~(((uint32_t)(cube & (1 << (tmp+8))) >> (tmp+8)) << 6);
|
||||
//PORTD |= (((~cube & (1 << tmp)) >> tmp) << 6);
|
||||
if ( (((cube >> tmp) >> 8) & 0x01) == 1 )
|
||||
PORTD &= ~(1 << 6);
|
||||
else
|
||||
PORTD |= (1 << 6);
|
||||
|
||||
//PORTD |= (1 << 6); // test to always off
|
||||
|
||||
cube_level++;
|
||||
if (cube_level > 2) cube_level = 0;
|
||||
|
||||
//cube_level++;
|
||||
//if (cube_level > 2) cube_level = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,17 +16,16 @@
|
|||
#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 = 0x0000000F; // Aktuelle Frame
|
||||
//volatile uint32_t cube = 0x07007007; // Aktuelles Frame
|
||||
volatile uint32_t cube = 0xffffffff; // Aktuelles Frame
|
||||
//volatile uint32_t cube = 0x00000000; // Aktuelles Frame
|
||||
// Bit Offset in Cube-Data
|
||||
volatile uint8_t cube_level = 0; // Ebene
|
||||
|
||||
// Prototypen
|
||||
void init(void);
|
||||
void loop(uint8_t);
|
||||
|
||||
extern void init_usb(void);
|
||||
extern void usbPoll(void);
|
||||
|
|
|
@ -12,35 +12,32 @@
|
|||
|
||||
usbMsgLen_t usbFunctionSetup(uchar data[8])
|
||||
{
|
||||
usbRequest_t *rq = (void *)data;
|
||||
usbRequest_t *rq = (void *)data;
|
||||
|
||||
if ( (rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_VENDOR )
|
||||
{
|
||||
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
|
||||
|
@ -48,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.
|
||||
|
@ -69,7 +65,7 @@ void init_usb(void)
|
|||
usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
|
||||
|
||||
i = 0;
|
||||
while(--i){ /* fake USB disconnect for > 250 ms */
|
||||
while(--i) { /* fake USB disconnect for > 250 ms */
|
||||
//wdt_reset();
|
||||
_delay_ms(1);
|
||||
//sleep_nop(255);
|
||||
|
|
|
@ -55,13 +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 volatile uint32_t cube; // Framebuffer
|
||||
|
||||
#endif // __usb_h__
|
||||
|
||||
|
|
Loading…
Reference in a new issue