mini-led-cube/firmware/usb.c

69 lines
2 KiB
C
Raw Normal View History

2011-10-15 11:31:44 +02:00
/* Name: usb.h by Kai Lauterbach
* Based on Project: hid-custom-rq example
* Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
* Author: Christian Starkjohann
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
*/
#include "usb.h"
/* ------------------------------------------------------------------------- */
usbMsgLen_t usbFunctionSetup(uchar data[8])
{
2011-11-29 19:39:57 +01:00
usbRequest_t *rq = (void *)data;
2011-10-15 11:31:44 +02:00
if ( (rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_VENDOR )
{
2011-12-18 19:35:47 +01:00
if ( rq->bRequest == CUSTOM_RQ_SET_FRAME )
{
2011-10-15 11:31:44 +02:00
2011-12-09 21:59:25 +01:00
if ( rq->wIndex.bytes[0] == 0 )
{
2011-12-17 22:03:57 +01:00
frame = (frame & (uint32_t)0xffff0000) |
2011-12-10 00:49:39 +01:00
( rq->wValue.bytes[0] +
2011-12-17 22:03:57 +01:00
(rq->wValue.bytes[1] << 8) );
2011-12-09 23:15:06 +01:00
} else {
2011-12-17 22:03:57 +01:00
frame = (frame & (uint32_t)0x0000ffff) |
((uint32_t)( rq->wValue.bytes[0] +
(rq->wValue.bytes[1] << 8) ) << 16);
}
2011-12-17 22:03:57 +01:00
} else if ( rq->bRequest == CUSTOM_RQ_EEPROM_STORE_FRAME )
{
2011-12-18 19:35:47 +01:00
eeprom_write_dword( &eep_anim[ rq->wIndex.bytes[0] ], frame );
} else if ( rq->bRequest == CUSTOM_RQ_SET_DELAY )
2011-12-18 19:35:47 +01:00
{
delay_max = rq->wValue.bytes[0];
2011-12-18 19:35:47 +01:00
} else if ( rq->bRequest == CUSTOM_RQ_SET_MODE )
{
2011-12-18 19:35:47 +01:00
mode = rq->wValue.bytes[0]; // 0 = stop; 1 = single; 2 = loop
2011-10-15 11:31:44 +02:00
}
2011-10-15 11:31:44 +02:00
}
return 0; /* default for not implemented requests: return no data back to host */
}
/* ------------------------------------------------------------------------- */
void init_usb(void)
{
2011-12-10 00:49:39 +01:00
uint8_t i;
2011-10-15 11:31:44 +02:00
usbInit();
usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
// fake USB disconnect for > 250 ms
while(--i)
{
asm volatile("nop"::);
2011-10-15 11:31:44 +02:00
}
2011-10-15 11:31:44 +02:00
usbDeviceConnect();
}
/* ------------------------------------------------------------------------- */