2011-01-19 07:27:20 +01:00
/* USB functions */
# ifndef _usb_h_
# define _usb_h_
2011-03-05 08:33:02 +01:00
# define USB_METHODS_INLINE
2011-01-19 07:27:20 +01:00
# include <inttypes.h>
# include "avrpins.h"
# include "max3421e.h"
# include "usbhost.h"
# include "usb_ch9.h"
2011-03-01 19:26:31 +01:00
# include "address.h"
2011-01-19 07:27:20 +01:00
# include <WProgram.h>
/* Common setup data constant combinations */
# define bmREQ_GET_DESCR USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_STANDARD|USB_SETUP_RECIPIENT_DEVICE //get descriptor request type
# define bmREQ_SET USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_STANDARD|USB_SETUP_RECIPIENT_DEVICE //set request type for all but 'set feature' and 'set interface'
# define bmREQ_CL_GET_INTF USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE //get interface request type
2011-03-01 19:26:31 +01:00
2011-01-19 07:27:20 +01:00
/* HID requests */
# define bmREQ_HIDOUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
# define bmREQ_HIDIN USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
# define bmREQ_HIDREPORT USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_STANDARD|USB_SETUP_RECIPIENT_INTERFACE
2011-03-01 19:26:31 +01:00
// D7 data transfer direction (0 - host-to-device, 1 - device-to-host)
// D6-5 Type (0- standard, 1 - class, 2 - vendor, 3 - reserved)
// D4-0 Recipient (0 - device, 1 - interface, 2 - endpoint, 3 - other, 4..31 - reserved)
// USB Device Classes
# define USB_CLASS_USE_CLASS_INFO 0x00 // Use Class Info in the Interface Descriptors
# define USB_CLASS_AUDIO 0x01 // Audio
# define USB_CLASS_COM_AND_CDC_CTRL 0x02 // Communications and CDC Control
# define USB_CLASS_HID 0x03 // HID
# define USB_CLASS_PHYSICAL 0x05 // Physical
# define USB_CLASS_IMAGE 0x06 // Image
# define USB_CLASS_PRINTER 0x07 // Printer
# define USB_CLASS_MASS_STORAGE 0x08 // Mass Storage
# define USB_CLASS_HUB 0x09 // Hub
# define USB_CLASS_CDC_DATA 0x0a // CDC-Data
# define USB_CLASS_SMART_CARD 0x0b // Smart-Card
# define USB_CLASS_CONTENT_SECURITY 0x0d // Content Security
# define USB_CLASS_VIDEO 0x0e // Video
# define USB_CLASS_PERSONAL_HEALTH 0x0f // Personal Healthcare
# define USB_CLASS_DIAGNOSTIC_DEVICE 0xdc // Diagnostic Device
# define USB_CLASS_WIRELESS_CTRL 0xe0 // Wireless Controller
# define USB_CLASS_MISC 0xef // Miscellaneous
# define USB_CLASS_APP_SPECIFIC 0xfe // Application Specific
# define USB_CLASS_VENDOR_SPECIFIC 0xff // Vendor Specific
// Hub Requests
# define bmREQ_CLEAR_HUB_FEATURE USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE
# define bmREQ_CLEAR_PORT_FEATURE USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER
# define bmREQ_CLEAR_TT_BUFFER USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER
# define bmREQ_GET_HUB_DESCRIPTOR USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE
# define bmREQ_GET_HUB_STATUS USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE
# define bmREQ_GET_PORT_STATUS USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER
# define bmREQ_RESET_TT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER
# define bmREQ_SET_HUB_DESCRIPTOR USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE
# define bmREQ_SET_HUB_FEATURE USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE
# define bmREQ_SET_PORT_FEATURE USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER
# define bmREQ_GET_TT_STATE USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER
# define bmREQ_STOP_TT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_OTHER
// Hub Class Requests
# define HUB_REQUEST_CLEAR_TT_BUFFER 8
# define HUB_REQUEST_RESET_TT 9
# define HUB_REQUEST_GET_TT_STATE 10
# define HUB_REQUEST_STOP_TT 11
// Hub Features
# define HUB_FEATURE_C_HUB_LOCAL_POWER 0
# define HUB_FEATURE_C_HUB_OVER_CURRENT 1
# define HUB_FEATURE_PORT_CONNECTION 0
# define HUB_FEATURE_PORT_ENABLE 1
# define HUB_FEATURE_PORT_SUSPEND 2
# define HUB_FEATURE_PORT_OVER_CURRENT 3
# define HUB_FEATURE_PORT_RESET 4
# define HUB_FEATURE_PORT_POWER 8
# define HUB_FEATURE_PORT_LOW_SPEED 9
# define HUB_FEATURE_C_PORT_CONNECTION 16
# define HUB_FEATURE_C_PORT_ENABLE 17
# define HUB_FEATURE_C_PORT_SUSPEND 18
# define HUB_FEATURE_C_PORT_OVER_CURRENT 19
# define HUB_FEATURE_C_PORT_RESET 20
# define HUB_FEATURE_PORT_TEST 21
# define HUB_FEATURE_PORT_INDICATOR 22
// Hub Port Test Modes
# define HUB_PORT_TEST_MODE_J 1
# define HUB_PORT_TEST_MODE_K 2
# define HUB_PORT_TEST_MODE_SE0_NAK 3
# define HUB_PORT_TEST_MODE_PACKET 4
# define HUB_PORT_TEST_MODE_FORCE_ENABLE 5
// Hub Port Indicator Color
# define HUB_PORT_INDICATOR_AUTO 0
# define HUB_PORT_INDICATOR_AMBER 1
# define HUB_PORT_INDICATOR_GREEN 2
# define HUB_PORT_INDICATOR_OFF 3
// Hub Port Status Bitmasks
# define bmHUB_PORT_STATUS_PORT_CONNECTION 0x0001
# define bmHUB_PORT_STATUS_PORT_ENABLE 0x0002
# define bmHUB_PORT_STATUS_PORT_SUSPEND 0x0004
# define bmHUB_PORT_STATUS_PORT_OVER_CURRENT 0x0008
# define bmHUB_PORT_STATUS_PORT_RESET 0x0010
# define bmHUB_PORT_STATUS_PORT_POWER 0x0100
# define bmHUB_PORT_STATUS_PORT_LOW_SPEED 0x0200
# define bmHUB_PORT_STATUS_PORT_HIGH_SPEED 0x0400
# define bmHUB_PORT_STATUS_PORT_TEST 0x0800
# define bmHUB_PORT_STATUS_PORT_INDICATOR 0x1000
// Hub Port Status Change Bitmasks (used one byte instead of two)
# define bmHUB_PORT_STATUS_C_PORT_CONNECTION 0x0001
# define bmHUB_PORT_STATUS_C_PORT_ENABLE 0x0002
# define bmHUB_PORT_STATUS_C_PORT_SUSPEND 0x0004
# define bmHUB_PORT_STATUS_C_PORT_OVER_CURRENT 0x0008
# define bmHUB_PORT_STATUS_C_PORT_RESET 0x0010
// Hub Status Bitmasks (used one byte instead of two)
# define bmHUB_STATUS_LOCAL_POWER_SOURCE 0x01
# define bmHUB_STATUS_OVER_CURRENT 0x12
// Hub Status Change Bitmasks (used one byte instead of two)
# define bmHUB_STATUS_C_LOCAL_POWER_SOURCE 0x01
# define bmHUB_STATUS_C_OVER_CURRENT 0x12
// Additional Error Codes
# define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED 0xD1
# define USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE 0xD2
# define USB_ERROR_UNABLE_TO_REGISTER_DEVICE_CLASS 0xD3
# define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL 0xD4
# define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL 0xD5
# define USB_ERROR_EPINFO_IS_NULL 0xD6
# define USB_ERROR_INVALID_ARGUMENT 0xD7
2011-03-05 08:33:02 +01:00
# define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE 0xD8
2011-04-16 07:24:10 +02:00
# define USB_ERROR_INVALID_MAX_PKT_SIZE 0xD9
# define USB_ERROR_EP_NOT_FOUND_IN_TBL 0xDA
2011-03-01 19:26:31 +01:00
class USBDeviceConfig
{
public :
2011-04-16 07:24:10 +02:00
virtual uint8_t Init ( uint8_t parent , uint8_t port , bool lowspeed ) = 0 ;
2011-03-05 08:33:02 +01:00
virtual uint8_t Release ( ) = 0 ;
virtual uint8_t Poll ( ) = 0 ;
2011-04-16 07:24:10 +02:00
virtual uint8_t GetAddress ( ) = 0 ;
2011-03-01 19:26:31 +01:00
} ;
# define USB_XFER_TIMEOUT 5000 //USB transfer timeout in milliseconds, per section 9.2.6.1 of USB 2.0 spec
# define USB_NAK_LIMIT 32000 //NAK limit for a transfer. o meand NAKs are not counted
# define USB_RETRY_LIMIT 3 //retry limit for a transfer
# define USB_SETTLE_DELAY 200 //settle delay in milliseconds
# define USB_NAK_NOWAIT 1 //used in Richard's PS2/Wiimote code
2011-01-19 07:27:20 +01:00
2011-04-16 07:24:10 +02:00
# define USB_NUMDEVICES 64 //number of USB devices
# define HUB_MAX_HUBS 7 // maximum number of hubs that can be attached to the host controller
2011-03-01 19:26:31 +01:00
# define HUB_PORT_RESET_DELAY 20 // hub port reset delay 10 ms recomended, can be up to 20 ms
/* USB state machine states */
2011-01-19 07:27:20 +01:00
# define USB_STATE_MASK 0xf0
# define USB_STATE_DETACHED 0x10
# define USB_DETACHED_SUBSTATE_INITIALIZE 0x11
# define USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE 0x12
# define USB_DETACHED_SUBSTATE_ILLEGAL 0x13
# define USB_ATTACHED_SUBSTATE_SETTLE 0x20
# define USB_ATTACHED_SUBSTATE_RESET_DEVICE 0x30
# define USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE 0x40
# define USB_ATTACHED_SUBSTATE_WAIT_SOF 0x50
# define USB_ATTACHED_SUBSTATE_GET_DEVICE_DESCRIPTOR_SIZE 0x60
# define USB_STATE_ADDRESSING 0x70
# define USB_STATE_CONFIGURING 0x80
# define USB_STATE_RUNNING 0x90
# define USB_STATE_ERROR 0xa0
2011-03-01 19:26:31 +01:00
2011-01-19 07:27:20 +01:00
// byte usb_task_state = USB_DETACHED_SUBSTATE_INITIALIZE
/* USB Setup Packet Structure */
typedef struct {
union { // offset description
uint8_t bmRequestType ; // 0 Bit-map of request type
struct {
uint8_t recipient : 5 ; // Recipient of the request
uint8_t type : 2 ; // Type of request
uint8_t direction : 1 ; // Direction of data X-fer
} ;
} ReqType_u ;
2011-03-01 19:26:31 +01:00
uint8_t bRequest ; // 1 Request
2011-01-19 07:27:20 +01:00
union {
unsigned int wValue ; // 2 Depends on bRequest
struct {
uint8_t wValueLo ;
uint8_t wValueHi ;
} ;
} wVal_u ;
unsigned int wIndex ; // 4 Depends on bRequest
unsigned int wLength ; // 6 Depends on bRequest
} SETUP_PKT , * PSETUP_PKT ;
2011-04-16 07:24:10 +02:00
///* device record structure */
//typedef struct
//{
// EpInfo *epinfo; //device endpoint information
// uint8_t devclass; //device class
//} DEV_RECORD;
2011-01-19 07:27:20 +01:00
2011-03-01 19:26:31 +01:00
struct HubDescriptor
{
uint8_t bDescLength ; // descriptor length
uint8_t bDescriptorType ; // descriptor type
uint8_t bNbrPorts ; // number of ports a hub equiped with
struct
{
uint16_t LogPwrSwitchMode : 2 ;
uint16_t CompoundDevice : 1 ;
uint16_t OverCurrentProtectMode : 2 ;
uint16_t TTThinkTime : 2 ;
uint16_t PortIndicatorsSupported : 1 ;
uint16_t Reserved : 8 ;
} ;
uint8_t bPwrOn2PwrGood ;
uint8_t bHubContrCurrent ;
} ;
2011-04-16 07:24:10 +02:00
// Base class for incomming data parser
class UsbReadParser
{
public :
virtual void Parse ( const uint8_t len , const uint8_t * pbuf , const uint16_t & offset ) = 0 ;
} ;
2011-03-01 19:26:31 +01:00
//typedef MAX3421e<P6, P3> MAX3421E; // Black Widdow
typedef MAX3421e < P10 , P9 > MAX3421E ; // Duemielanove
2011-01-19 07:27:20 +01:00
class USB : public MAX3421E
{
2011-03-01 19:26:31 +01:00
AddressPoolImpl < USB_NUMDEVICES > addrPool ;
USBDeviceConfig * devConfig [ USB_NUMDEVICES ] ;
uint8_t devConfigIndex ;
2011-04-16 07:24:10 +02:00
uint8_t bmHubPre ;
2011-03-01 19:26:31 +01:00
2011-01-19 07:27:20 +01:00
public :
USB ( void ) ;
2011-03-01 19:26:31 +01:00
2011-04-16 07:24:10 +02:00
void SetHubPreMask ( ) { bmHubPre | = bmHUBPRE ; } ;
void ResetHubPreMask ( ) { bmHubPre & = ( ~ bmHUBPRE ) ; } ;
2011-03-05 08:33:02 +01:00
AddressPool & GetAddressPool ( )
{
return ( AddressPool & ) addrPool ;
} ;
2011-03-01 19:26:31 +01:00
uint8_t RegisterDeviceClass ( USBDeviceConfig * pdev )
{
for ( uint8_t i = 0 ; i < USB_NUMDEVICES ; i + + )
{
if ( ! devConfig [ i ] )
{
devConfig [ i ] = pdev ;
return 0 ;
}
}
return USB_ERROR_UNABLE_TO_REGISTER_DEVICE_CLASS ;
} ;
void ForEachUsbDevice ( UsbDeviceHandleFunc pfunc )
{
addrPool . ForEachUsbDevice ( pfunc ) ;
} ;
uint8_t getUsbTaskState ( void ) ;
2011-01-19 07:27:20 +01:00
void setUsbTaskState ( uint8_t state ) ;
2011-03-01 19:26:31 +01:00
2011-04-16 07:24:10 +02:00
EpInfo * getEpInfoEntry ( uint8_t addr , uint8_t ep ) ;
uint8_t setEpInfoEntry ( uint8_t addr , uint8_t epcount , EpInfo * eprecord_ptr ) ;
2011-03-01 19:26:31 +01:00
2011-04-16 07:24:10 +02:00
uint8_t ctrlReq ( uint8_t addr , uint8_t ep , uint8_t bmReqType , uint8_t bRequest , uint8_t wValLo , uint8_t wValHi , unsigned int wInd , unsigned int nbytes , uint8_t * dataptr ) ;
2011-03-01 19:26:31 +01:00
/* Control requests */
2011-04-16 07:24:10 +02:00
uint8_t getDevDescr ( uint8_t addr , uint8_t ep , unsigned int nbytes , uint8_t * dataptr ) ;
uint8_t getConfDescr ( uint8_t addr , uint8_t ep , unsigned int nbytes , uint8_t conf , uint8_t * dataptr ) ;
uint8_t getStrDescr ( uint8_t addr , uint8_t ep , unsigned int nbytes , uint8_t index , unsigned int langid , uint8_t * dataptr ) ;
uint8_t setAddr ( uint8_t oldaddr , uint8_t ep , uint8_t newaddr ) ;
uint8_t setConf ( uint8_t addr , uint8_t ep , uint8_t conf_value ) ;
2011-01-19 07:27:20 +01:00
/**/
2011-04-16 07:24:10 +02:00
uint8_t setProto ( uint8_t addr , uint8_t ep , uint8_t interface , uint8_t protocol ) ;
uint8_t getProto ( uint8_t addr , uint8_t ep , uint8_t interface , uint8_t * dataptr ) ;
uint8_t getReportDescr ( uint8_t addr , uint8_t ep , unsigned int nbytes , uint8_t * dataptr ) ;
uint8_t setReport ( uint8_t addr , uint8_t ep , unsigned int nbytes , uint8_t interface , uint8_t report_type , uint8_t report_id , uint8_t * dataptr ) ;
uint8_t getReport ( uint8_t addr , uint8_t ep , unsigned int nbytes , uint8_t interface , uint8_t report_type , uint8_t report_id , uint8_t * dataptr ) ;
uint8_t getIdle ( uint8_t addr , uint8_t ep , uint8_t interface , uint8_t reportID , uint8_t * dataptr ) ;
uint8_t setIdle ( uint8_t addr , uint8_t ep , uint8_t interface , uint8_t reportID , uint8_t duration ) ;
2011-01-19 07:27:20 +01:00
/**/
2011-04-16 07:24:10 +02:00
uint8_t ctrlData ( uint8_t addr , uint8_t ep , unsigned int nbytes , uint8_t * dataptr , boolean direction ) ;
uint8_t ctrlStatus ( uint8_t ep , boolean direction , uint16_t nak_limit ) ;
uint8_t inTransfer ( uint8_t addr , uint8_t ep , unsigned int nbytes , uint8_t * data ) ;
uint8_t outTransfer ( uint8_t addr , uint8_t ep , unsigned int nbytes , uint8_t * data ) ;
uint8_t dispatchPkt ( uint8_t token , uint8_t ep , uint16_t nak_limit ) ;
2011-03-01 19:26:31 +01:00
// Hub Methods
2011-04-16 07:24:10 +02:00
uint8_t ClearHubFeature ( uint8_t addr , uint8_t ep , uint8_t fid ) ;
uint8_t ClearPortFeature ( uint8_t addr , uint8_t ep , uint8_t fid , uint8_t port , uint8_t sel = 0 ) ;
uint8_t GetHubDescriptor ( uint8_t addr , uint8_t ep , uint8_t index , uint16_t nbytes , uint8_t * dataptr ) ;
uint8_t GetHubStatus ( uint8_t addr , uint8_t ep , uint16_t nbytes , uint8_t * dataptr ) ;
uint8_t GetPortStatus ( uint8_t addr , uint8_t ep , uint8_t port , uint16_t nbytes , uint8_t * dataptr ) ;
uint8_t SetHubDescriptor ( uint8_t addr , uint8_t ep , uint8_t port , uint16_t nbytes , uint8_t * dataptr ) ;
uint8_t SetHubFeature ( uint8_t addr , uint8_t ep , uint8_t fid ) ;
uint8_t SetPortFeature ( uint8_t addr , uint8_t ep , uint8_t fid , uint8_t port , uint8_t sel = 0 ) ;
2011-03-01 19:26:31 +01:00
uint8_t HubPortPowerOn ( uint8_t addr , uint8_t port ) ;
uint8_t HubPortReset ( uint8_t addr , uint8_t port ) ;
uint8_t HubClearPortFeatures ( uint8_t addr , uint8_t port , uint8_t bm_features ) ;
void PrintHubStatus ( /*USB *usbptr,*/ uint8_t addr ) ;
2011-01-19 07:27:20 +01:00
void Task ( void ) ;
2011-03-01 19:26:31 +01:00
2011-04-16 07:24:10 +02:00
uint8_t DefaultAddressing ( uint8_t parent , uint8_t port , bool lowspeed ) ;
uint8_t Configuring ( uint8_t parent , uint8_t port , bool lowspeed ) ;
uint8_t ReleaseDevice ( uint8_t addr ) ;
2011-03-01 19:26:31 +01:00
2011-04-16 07:24:10 +02:00
//typedef void (*USBREADCALLBACK)(uint16_t nbytes, uint8_t *data, uint16_t offset);
//uint8_t ctrlReq( uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi,
// uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t* dataptr, USBREADCALLBACK pf);
uint8_t ctrlReq ( uint8_t addr , uint8_t ep , uint8_t bmReqType , uint8_t bRequest , uint8_t wValLo , uint8_t wValHi ,
uint16_t wInd , uint16_t total , uint16_t nbytes , uint8_t * dataptr , UsbReadParser * p ) ;
2011-01-19 07:27:20 +01:00
private :
void init ( ) ;
2011-04-16 07:24:10 +02:00
uint8_t SetAddress ( uint8_t addr , uint8_t ep , EpInfo * * ppep , uint16_t & nak_limit ) ;
uint8_t OutTransfer ( EpInfo * pep , uint16_t nak_limit , unsigned int nbytes , uint8_t * data ) ;
uint8_t InTransfer ( EpInfo * pep , uint16_t nak_limit , unsigned int nbytes , uint8_t * data ) ;
2011-01-19 07:27:20 +01:00
} ;
2011-04-16 07:24:10 +02:00
//#if defined(USB_METHODS_INLINE)
2011-01-19 07:27:20 +01:00
//get device descriptor
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : getDevDescr ( uint8_t addr , uint8_t ep , unsigned int nbytes , uint8_t * dataptr ) {
return ( ctrlReq ( addr , ep , bmREQ_GET_DESCR , USB_REQUEST_GET_DESCRIPTOR , 0x00 , USB_DESCRIPTOR_DEVICE , 0x0000 , nbytes , dataptr ) ) ;
2011-01-19 07:27:20 +01:00
}
//get configuration descriptor
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : getConfDescr ( uint8_t addr , uint8_t ep , unsigned int nbytes , uint8_t conf , uint8_t * dataptr ) {
return ( ctrlReq ( addr , ep , bmREQ_GET_DESCR , USB_REQUEST_GET_DESCRIPTOR , conf , USB_DESCRIPTOR_CONFIGURATION , 0x0000 , nbytes , dataptr ) ) ;
2011-01-19 07:27:20 +01:00
}
//get string descriptor
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : getStrDescr ( uint8_t addr , uint8_t ep , unsigned int nuint8_ts , uint8_t index , unsigned int langid , uint8_t * dataptr ) {
return ( ctrlReq ( addr , ep , bmREQ_GET_DESCR , USB_REQUEST_GET_DESCRIPTOR , index , USB_DESCRIPTOR_STRING , langid , nuint8_ts , dataptr ) ) ;
2011-01-19 07:27:20 +01:00
}
//set address
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : setAddr ( uint8_t oldaddr , uint8_t ep , uint8_t newaddr ) {
return ( ctrlReq ( oldaddr , ep , bmREQ_SET , USB_REQUEST_SET_ADDRESS , newaddr , 0x00 , 0x0000 , 0x0000 , NULL ) ) ;
2011-01-19 07:27:20 +01:00
}
//set configuration
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : setConf ( uint8_t addr , uint8_t ep , uint8_t conf_value ) {
return ( ctrlReq ( addr , ep , bmREQ_SET , USB_REQUEST_SET_CONFIGURATION , conf_value , 0x00 , 0x0000 , 0x0000 , NULL ) ) ;
2011-01-19 07:27:20 +01:00
}
//class requests
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : setProto ( uint8_t addr , uint8_t ep , uint8_t interface , uint8_t protocol ) {
return ( ctrlReq ( addr , ep , bmREQ_HIDOUT , HID_REQUEST_SET_PROTOCOL , protocol , 0x00 , interface , 0x0000 , NULL ) ) ;
2011-01-19 07:27:20 +01:00
}
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : getProto ( uint8_t addr , uint8_t ep , uint8_t interface , uint8_t * dataptr ) {
return ( ctrlReq ( addr , ep , bmREQ_HIDIN , HID_REQUEST_GET_PROTOCOL , 0x00 , 0x00 , interface , 0x0001 , dataptr ) ) ;
2011-01-19 07:27:20 +01:00
}
//get HID report descriptor
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : getReportDescr ( uint8_t addr , uint8_t ep , unsigned int nbytes , uint8_t * dataptr ) {
return ( ctrlReq ( addr , ep , bmREQ_HIDREPORT , USB_REQUEST_GET_DESCRIPTOR , 0x00 , HID_DESCRIPTOR_REPORT , 0x0000 , nbytes , dataptr ) ) ;
2011-01-19 07:27:20 +01:00
}
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : setReport ( uint8_t addr , uint8_t ep , unsigned int nbytes , uint8_t interface , uint8_t report_type , uint8_t report_id , uint8_t * dataptr ) {
return ( ctrlReq ( addr , ep , bmREQ_HIDOUT , HID_REQUEST_SET_REPORT , report_id , report_type , interface , nbytes , dataptr ) ) ;
2011-01-19 07:27:20 +01:00
}
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : getReport ( uint8_t addr , uint8_t ep , unsigned int nbytes , uint8_t interface , uint8_t report_type , uint8_t report_id , uint8_t * dataptr ) {
return ( ctrlReq ( addr , ep , bmREQ_HIDIN , HID_REQUEST_GET_REPORT , report_id , report_type , interface , nbytes , dataptr ) ) ;
2011-01-19 07:27:20 +01:00
}
/* returns one byte of data in dataptr */
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : getIdle ( uint8_t addr , uint8_t ep , uint8_t interface , uint8_t reportID , uint8_t * dataptr ) {
return ( ctrlReq ( addr , ep , bmREQ_HIDIN , HID_REQUEST_GET_IDLE , reportID , 0 , interface , 0x0001 , dataptr ) ) ;
2011-01-19 07:27:20 +01:00
}
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : setIdle ( uint8_t addr , uint8_t ep , uint8_t interface , uint8_t reportID , uint8_t duration ) {
return ( ctrlReq ( addr , ep , bmREQ_HIDOUT , HID_REQUEST_SET_IDLE , reportID , duration , interface , 0x0000 , NULL ) ) ;
2011-01-19 07:27:20 +01:00
}
2011-03-01 19:26:31 +01:00
// Clear Hub Feature
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : ClearHubFeature ( uint8_t addr , uint8_t ep , uint8_t fid )
2011-03-01 19:26:31 +01:00
{
2011-04-16 07:24:10 +02:00
return ( ctrlReq ( addr , ep , bmREQ_CLEAR_HUB_FEATURE , USB_REQUEST_CLEAR_FEATURE , fid , 0 , 0 , 0 , NULL ) ) ;
2011-03-01 19:26:31 +01:00
}
// Clear Port Feature
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : ClearPortFeature ( uint8_t addr , uint8_t ep , uint8_t fid , uint8_t port , uint8_t sel )
2011-03-01 19:26:31 +01:00
{
2011-04-16 07:24:10 +02:00
return ( ctrlReq ( addr , ep , bmREQ_CLEAR_PORT_FEATURE , USB_REQUEST_CLEAR_FEATURE , fid , 0 , ( ( 0x0000 | port ) | ( sel < < 8 ) ) , 0 , NULL ) ) ;
2011-03-01 19:26:31 +01:00
}
// Get Hub Descriptor
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : GetHubDescriptor ( uint8_t addr , uint8_t ep , uint8_t index , uint16_t nbytes , uint8_t * dataptr )
2011-03-01 19:26:31 +01:00
{
2011-04-16 07:24:10 +02:00
return ( ctrlReq ( addr , ep , bmREQ_GET_HUB_DESCRIPTOR , USB_REQUEST_GET_DESCRIPTOR , index , 0x29 , 0 , nbytes , dataptr ) ) ;
2011-03-01 19:26:31 +01:00
}
// Get Hub Status
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : GetHubStatus ( uint8_t addr , uint8_t ep , uint16_t nbytes , uint8_t * dataptr )
2011-03-01 19:26:31 +01:00
{
2011-04-16 07:24:10 +02:00
return ( ctrlReq ( addr , ep , bmREQ_GET_HUB_STATUS , USB_REQUEST_GET_STATUS , 0 , 0 , 0x0000 , nbytes , dataptr ) ) ;
2011-03-01 19:26:31 +01:00
}
// Get Port Status
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : GetPortStatus ( uint8_t addr , uint8_t ep , uint8_t port , uint16_t nbytes , uint8_t * dataptr )
2011-03-01 19:26:31 +01:00
{
2011-04-16 07:24:10 +02:00
return ( ctrlReq ( addr , ep , bmREQ_GET_PORT_STATUS , USB_REQUEST_GET_STATUS , 0 , 0 , port , nbytes , dataptr ) ) ;
2011-03-01 19:26:31 +01:00
}
// Set Hub Descriptor
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : SetHubDescriptor ( uint8_t addr , uint8_t ep , uint8_t port , uint16_t nbytes , uint8_t * dataptr )
2011-03-01 19:26:31 +01:00
{
2011-04-16 07:24:10 +02:00
return ( ctrlReq ( addr , ep , bmREQ_SET_HUB_DESCRIPTOR , USB_REQUEST_SET_DESCRIPTOR , 0 , 0 , port , nbytes , dataptr ) ) ;
2011-03-01 19:26:31 +01:00
}
// Set Hub Feature
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : SetHubFeature ( uint8_t addr , uint8_t ep , uint8_t fid )
2011-03-01 19:26:31 +01:00
{
2011-04-16 07:24:10 +02:00
return ( ctrlReq ( addr , ep , bmREQ_SET_HUB_FEATURE , USB_REQUEST_SET_FEATURE , fid , 0 , 0 , 0 , NULL ) ) ;
2011-03-01 19:26:31 +01:00
}
// Set Port Feature
2011-04-16 07:24:10 +02:00
inline uint8_t USB : : SetPortFeature ( uint8_t addr , uint8_t ep , uint8_t fid , uint8_t port , uint8_t sel )
2011-03-01 19:26:31 +01:00
{
2011-04-16 07:24:10 +02:00
return ( ctrlReq ( addr , ep , bmREQ_SET_PORT_FEATURE , USB_REQUEST_SET_FEATURE , fid , 0 , ( ( ( 0x0000 | sel ) < < 8 ) | port ) , 0 , NULL ) ) ;
2011-03-01 19:26:31 +01:00
}
2011-04-16 07:24:10 +02:00
//#endif // defined(USB_METHODS_INLINE)
2011-03-05 08:33:02 +01:00
2011-01-19 07:27:20 +01:00
# endif //_usb_h_