Custom USB requests changed.

This commit is contained in:
Kai Lauterbach 2011-12-09 21:59:25 +01:00
parent b92b8953a6
commit e6a5e55a3e
3 changed files with 21 additions and 29 deletions

View file

@ -29,11 +29,11 @@ respectively.
int main(int argc, char **argv)
{
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 vid, pid;
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 vid, pid;
usb_init();
@ -69,9 +69,9 @@ int vid, pid;
// 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);
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, 0x7007, 0, 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);
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, 0x0700, 1, 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);
@ -80,13 +80,13 @@ int vid, pid;
int i = 0;
for (i = 0; i < 27; i++)
{
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 1, i, buffer, 0, 300);
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_LED, 1, i, buffer, 0, 300);
sleep(1);
}
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);
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_LED, 0, i, buffer, 0, 300);
sleep(1);
}

View file

@ -16,17 +16,9 @@
#ifndef __REQUESTS_H_INCLUDED__
#define __REQUESTS_H_INCLUDED__
#define CUSTOM_RQ_SET_STATUS 1
/* Set the LED status. Control-OUT.
* The requested status is passed in the "wValue" field of the control
* transfer. No OUT data is sent. Bit 0 of the low byte of wValue controls
* the LED.
*/
#define CUSTOM_RQ_SET_LED 1
#define CUSTOM_RQ_SET_FRAME 2
#define CUSTOM_RQ_GET_STATUS 2
/* Get the current LED status. Control-IN.
* This control transfer involves a 1 byte data phase where the device sends
* the current status to the host. The status is in bit 0 of the byte.
*/
//#define CUSTOM_RQ_GET_STATUS 255
#endif /* __REQUESTS_H_INCLUDED__ */

View file

@ -16,25 +16,25 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
if ( (rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_VENDOR )
{
if ( rq->bRequest == CUSTOM_RQ_SET_STATUS )
if ( rq->bRequest == CUSTOM_RQ_SET_LED )
{
if ( rq->wValue.bytes[0] == 1 )
cube |= ((uint32_t)1 << rq->wIndex.bytes[0]);
else
cube &= ~((uint32_t)1 << rq->wIndex.bytes[0]);
} else if ( rq->bRequest == CUSTOM_RQ_SET_FRAME )
{
if ( rq->wIndex.bytes[0] == 27 )
if ( rq->wIndex.bytes[0] == 0 )
{
cube = (cube & (uint32_t)0xffff0000) |
rq->wValue.bytes[0] +
(rq->wValue.bytes[1] << 8);
} else if ( rq->wIndex.bytes[0] == 28 )
} else if ( rq->wIndex.bytes[0] == 1 )
{
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]);
}
//} else if ( rq->bRequest == CUSTOM_RQ_GET_STATUS ) {