Hi Jan,
I just want to confirm, which of these two are correct.
From example given by manufacturer and from example given by Tsuneo.
Manufacturer's example:
//From example given by manufacturer
switch(SETUP.bmRequestType) // Determine if recipient was device,
{ // interface, or EP
case OUT_DEVICE: //<--------Defined below as 0x80, is this supposed to be IN_DEVICE? Bit 7 = 1 which is an IN, from USB 2.0 specification Table 9-2 p.248
if (SETUP.wIndex.c[MSB] || SETUP.wIndex.c[LSB])
{
Force_Stall (); // Send stall if request is invalid
}
else ...
// Define bmRequestType bitmaps
#define IN_DEVICE 0x00 // Request made to device,
// direction is IN
#define OUT_DEVICE 0x80 // Request made to device,
// direction is OUT
#define IN_INTERFACE 0x01 // Request made to interface,
// direction is IN
#define OUT_INTERFACE 0x81 // Request made to interface,
// direction is OUT
#define IN_ENDPOINT 0x02 // Request made to endpoint,
// direction is IN
#define OUT_ENDPOINT 0x82 // Request made to endpoint,
// direction is OUT
Tsuneo's Example:
//From example given by Tsuneo - Keil_USB_HID_Composite
switch( Setup.bmRequestType )
{
case IN_DEVICE: //<-------Defined below as 0x80, which is an IN, from USB Specification 2.0
if ( Setup.wIndex.i == 0 ) // Valid when wIndex equals to zero
{
// send 0x00, indicating bus power and no remote wake-up supported
DataPtr = (BYTE*)&ZERO_PACKET;
setup_handled = TRUE;
}
break;
case IN_INTERFACE: // See if recipient was interface
// Valid if device is configured and existing interface index
if ( (USB_State == DEV_CONFIGURED) && (Setup.wIndex.i < DSC_NUM_INTERFACE) )
{
// Status packet always returns 0x00
DataPtr = (BYTE*)&ZERO_PACKET;
setup_handled = TRUE;
}
break;
case IN_ENDPOINT: // See if recipient was an endpoint
// Make sure device is configured and index msb = 0x00
if ((USB_State == DEV_CONFIGURED) && (Setup.wIndex.c[MSB] == 0) )
{
// Device Request Direction (bmRequestType bit7)
#define DRD_MASK 0x80 // Mask for device request direction
#define DRD_OUT 0x00 // OUT: host to device
#define DRD_IN 0x80 // IN: device to host
// Device Request Type (bmRequestType bit6-5)
#define DRT_MASK 0x60 // Mask for device request type
#define DRT_STD 0x00 // Standard device request
#define DRT_CLASS 0x20 // Class specific request
#define DRT_VENDOR 0x40 // Vendor specific request
// Device Request Recipient (bmRequestType bit4-0)
#define DRR_MASK 0x1F // Mask for device request recipient
#define DRR_DEVICE 0x00 // Device
#define DRR_INTERFACE 0x01 // Interface
#define DRR_ENDPOINT 0x02 // Endpoint
// Define bmRequestType bitmaps
#define OUT_DEVICE (DRD_OUT | DRT_STD | DRR_DEVICE) // Request made to device,
#define IN_DEVICE (DRD_IN | DRT_STD | DRR_DEVICE) // Request made to device,
#define OUT_INTERFACE (DRD_OUT | DRT_STD | DRR_INTERFACE) // Request made to interface,
#define IN_INTERFACE (DRD_IN | DRT_STD | DRR_INTERFACE) // Request made to interface,
#define OUT_ENDPOINT (DRD_OUT | DRT_STD | DRR_ENDPOINT) // Request made to endpoint,
#define IN_ENDPOINT (DRD_IN | DRT_STD | DRR_ENDPOINT) // Request made to endpoint,
I have a feeling that the example given by the manufacturer contains some typo error, the value is correct but the name is misleading.
Is my thought correct?
thanks
gi