5 Copyright (C) 2006 by Michal Schulz
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Library General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU Library General Public
19 License along with this program; if not, write to the
20 Free Software Foundation, Inc.,
21 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include <exec/ports.h>
27 #include <exec/interrupts.h>
28 #include <hidd/hidd.h>
30 #include <utility/utility.h>
31 #include <utility/tagitem.h>
32 #include <usb/usb_core.h>
45 #define CLID_Hidd_USB "Bus::USB"
46 #define IID_Hidd_USB "IBus::USB"
48 #define HiddUSBAttrBase __IHidd_USB
50 #ifndef __OOP_NOATTRBASES__
51 extern OOP_AttrBase HiddUSBAttrBase
;
55 moHidd_USB_AttachDriver
,
56 moHidd_USB_DetachDriver
,
58 moHidd_USB_AllocAddress
,
59 moHidd_USB_FreeAddress
,
60 moHidd_USB_NewDevice
, // Internal call used to attach new USB devices to the system
71 #define aHidd_USB_Bus (HiddUSBAttrBase + aoHidd_USB_Bus)
73 #define IS_USB_ATTR(attr, idx) \
74 (((idx) = (attr) - HiddUSBAttrBase) < num_Hidd_USB_Attrs)
76 /// The Method arguments for USB::AttachDriver call
77 struct pHidd_USB_AttachDriver
{
79 OOP_Object
*driverObject
;
82 struct pHidd_USB_DetachDriver
{
84 OOP_Object
*driverObject
;
87 struct pHidd_USB_AddClass
{
89 const char *className
;
92 struct pHidd_USB_AllocAddress
{
94 OOP_Object
*driverObject
;
97 struct pHidd_USB_FreeAddress
{
99 OOP_Object
*driverObject
;
103 struct pHidd_USB_NewDevice
{
105 OOP_Object
*hub
; // New device attached to this hub
106 usb_device_descriptor_t
*descriptor
;
114 #define CLID_Hidd_USBDevice "Hidd::USBDevice"
115 #define IID_Hidd_USBDevice "IHidd::USBDevice"
117 #define HiddUSBDeviceAttrBase __IHidd_USBDevice
119 #ifndef __OOP_NOATTRBASES__
120 extern OOP_AttrBase HiddUSBDeviceAttrBase
;
124 moHidd_USBDevice_GetString
,
125 moHidd_USBDevice_CreatePipe
,
126 moHidd_USBDevice_DeletePipe
,
127 moHidd_USBDevice_ControlMessage
,
128 moHidd_USBDevice_GetDescriptor
,
129 moHidd_USBDevice_GetConfigDescriptor
,
130 moHidd_USBDevice_GetDeviceDescriptor
,
131 moHidd_USBDevice_GetStatus
,
132 moHidd_USBDevice_Configure
,
133 moHidd_USBDevice_GetInterface
,
134 moHidd_USBDevice_GetEndpoint
,
135 moHidd_USBDevice_BulkTransfer
,
136 moHidd_USBDevice_SetTimeout
,
138 NUM_HIDD_USBDEVICE_METHODS
142 aoHidd_USBDevice_Address
,
143 aoHidd_USBDevice_Bus
,
144 aoHidd_USBDevice_Hub
,
145 aoHidd_USBDevice_ProductID
,
146 aoHidd_USBDevice_VendorID
,
147 aoHidd_USBDevice_Interface
,
148 aoHidd_USBDevice_InterfaceNumber
,
150 aoHidd_USBDevice_ProductName
,
151 aoHidd_USBDevice_ManufacturerName
,
152 aoHidd_USBDevice_SerialNumber
,
154 aoHidd_USBDevice_Fast
,
155 aoHidd_USBDevice_MaxPacketSize
,
157 aoHidd_USBDevice_Next
,
159 num_Hidd_USBDevice_Attrs
162 #define aHidd_USBDevice_Address (HiddUSBDeviceAttrBase + aoHidd_USBDevice_Address)
163 #define aHidd_USBDevice_Bus (HiddUSBDeviceAttrBase + aoHidd_USBDevice_Bus)
164 #define aHidd_USBDevice_Hub (HiddUSBDeviceAttrBase + aoHidd_USBDevice_Hub)
165 #define aHidd_USBDevice_ProductID (HiddUSBDeviceAttrBase + aoHidd_USBDevice_ProductID)
166 #define aHidd_USBDevice_VendorID (HiddUSBDeviceAttrBase + aoHidd_USBDevice_VendorID)
167 #define aHidd_USBDevice_Interface (HiddUSBDeviceAttrBase + aoHidd_USBDevice_Interface)
168 #define aHidd_USBDevice_InterfaceNumber (HiddUSBDeviceAttrBase + aoHidd_USBDevice_InterfaceNumber)
169 #define aHidd_USBDevice_ProductName (HiddUSBDeviceAttrBase + aoHidd_USBDevice_ProductName)
170 #define aHidd_USBDevice_ManufacturerName (HiddUSBDeviceAttrBase + aoHidd_USBDevice_ManufacturerName)
171 #define aHidd_USBDevice_SerialNumber (HiddUSBDeviceAttrBase + aoHidd_USBDevice_SerialNumber)
173 #define aHidd_USBDevice_Fast (HiddUSBDeviceAttrBase + aoHidd_USBDevice_Fast)
174 #define aHidd_USBDevice_MaxPacketSize (HiddUSBDeviceAttrBase + aoHidd_USBDevice_MaxPacketSize)
176 #define aHidd_USBDevice_Next (HiddUSBDeviceAttrBase + aoHidd_USBDevice_Next)
178 #define IS_USBDEVICE_ATTR(attr, idx) \
179 (((idx) = (attr) - HiddUSBDeviceAttrBase) < num_Hidd_USBDevice_Attrs)
181 struct pHidd_USBDevice_GetDescriptor
{
189 struct pHidd_USBDevice_GetConfigDescriptor
{
192 usb_config_descriptor_t
*descriptor
;
195 struct pHidd_USBDevice_GetDeviceDescriptor
{
197 usb_device_descriptor_t
*descriptor
;
200 struct pHidd_USBDevice_GetStatus
{
202 usb_status_t
*status
;
205 struct pHidd_USBDevice_GetString
{
209 usb_string_descriptor_t
*string
;
212 struct pHidd_USBDevice_ControlMessage
{
215 USBDevice_Request
*request
;
220 struct pHidd_USBDevice_CreatePipe
{
222 enum USB_PipeType type
;
229 struct pHidd_USBDevice_DeletePipe
{
234 struct pHidd_USBDevice_Configure
{
239 struct pHidd_USBDevice_GetInterface
{
244 struct pHidd_USBDevice_GetEndpoint
{
250 struct pHidd_USBDevice_BulkTransfer
{
257 struct pHidd_USBDevice_SetTimeout
{
268 #define CLID_Hidd_USBHub "Hidd::USBHub"
269 #define IID_Hidd_USBHub "IHidd::USBHub"
271 #define HiddUSBHubAttrBase __IHidd_USBHub
273 #ifndef __OOP_NOATTRBASES__
274 extern OOP_AttrBase HiddUSBHubAttrBase
;
279 moHidd_USBHub_PortEnable
,
280 moHidd_USBHub_PortReset
,
281 moHidd_USBHub_GetPortStatus
,
282 moHidd_USBHub_GetHubStatus
,
283 moHidd_USBHub_ClearHubFeature
,
284 moHidd_USBHub_SetHubFeature
,
285 moHidd_USBHub_ClearPortFeature
,
286 moHidd_USBHub_SetPortFeature
,
287 moHidd_USBHub_GetChild
,
288 moHidd_USBHub_GetHubDescriptor
,
290 NUM_HIDD_USBHUB_METHODS
293 struct pHidd_USBHub_OnOff
{
298 struct pHidd_USBHub_PortEnable
{
304 struct pHidd_USBHub_PortReset
{
309 struct pHidd_USBHub_GetPortStatus
{
312 usb_port_status_t
*status
;
315 struct pHidd_USBHub_GetHubStatus
{
317 usb_hub_status_t
*status
;
320 struct pHidd_USBHub_ClearHubFeature
{
325 struct pHidd_USBHub_SetHubFeature
{
330 struct pHidd_USBHub_ClearPortFeature
{
336 struct pHidd_USBHub_SetPortFeature
{
342 struct pHidd_USBHub_GetChild
{
347 struct pHidd_USBHub_GetHubDescriptor
{
349 usb_hub_descriptor_t
*descriptor
;
353 aoHidd_USBHub_IsRoot
,
354 aoHidd_USBHub_IsCompound
,
355 aoHidd_USBHub_HubCurrent
,
356 aoHidd_USBHub_NumPorts
,
358 num_Hidd_USBHub_Attrs
361 #define aHidd_USBHub_IsRoot (HiddUSBHubAttrBase + aoHidd_USBHub_IsRoot)
362 #define aHidd_USBHub_IsCompound (HiddUSBHubAttrBase + aoHidd_USBHub_IsCompound)
363 #define aHidd_USBHub_HubCurrent (HiddUSBHubAttrBase + aoHidd_USBHub_HubCurrent)
364 #define aHidd_USBHub_NumPorts (HiddUSBHubAttrBase + aoHidd_USBHub_NumPorts)
366 #define IS_USBHUB_ATTR(attr, idx) \
367 (((idx) = (attr) - HiddUSBHubAttrBase) < num_Hidd_USBHub_Attrs)
370 #define CLID_Hidd_USBDrv "Hidd::USBDriver"
371 #define IID_Hidd_USBDrv "IHidd::USBDriver"
373 #define HiddUSBDrvAttrBase __IHidd_USBDrv
375 #ifndef __OOP_NOATTRBASES__
376 extern OOP_AttrBase HiddUSBDrvAttrBase
;
380 moHidd_USBDrv_CreatePipe
,
381 moHidd_USBDrv_DeletePipe
,
382 moHidd_USBDrv_ControlTransfer
,
383 moHidd_USBDrv_AddInterrupt
,
384 moHidd_USBDrv_RemInterrupt
,
385 moHidd_USBDrv_BulkTransfer
,
386 moHidd_USBDrv_SetTimeout
,
388 NUM_HIDD_USBDRV_METHODS
392 num_Hidd_USBDrv_Attrs
395 #define IS_USBDRV_ATTR(attr, idx) \
396 (((idx) = (attr) - HiddUSBDrvAttrBase) < num_Hidd_USBDrv_Attrs)
398 struct pHidd_USBDrv_CreatePipe
{
400 enum USB_PipeType type
;
409 struct pHidd_USBDrv_DeletePipe
{
414 struct pHidd_USBDrv_ControlTransfer
{
417 USBDevice_Request
*request
;
422 struct pHidd_USBDrv_BulkTransfer
{
429 struct pHidd_USBDrv_AddInterrupt
{
434 struct Interrupt
*interrupt
;
437 struct pHidd_USBDrv_RemInterrupt
{
440 struct Interrupt
*interrupt
;
443 struct pHidd_USBDrv_SetTimeout
{
451 BOOL
HIDD_USB_AttachDriver(OOP_Object
*obj
, OOP_Object
*driver
);
452 BOOL
HIDD_USB_DetachDriver(OOP_Object
*obj
, OOP_Object
*driver
);
453 void HIDD_USB_AddClass(OOP_Object
*obj
, const char *className
);
454 uint8_t HIDD_USB_AllocAddress(OOP_Object
*obj
, OOP_Object
*driver
);
455 void HIDD_USB_FreeAddress(OOP_Object
*obj
, OOP_Object
*driver
, uint8_t address
);
456 OOP_Object
*HIDD_USB_NewDevice(OOP_Object
*obj
, OOP_Object
*hub
, BOOL fast
);
458 BOOL
HIDD_USBDevice_GetDescriptor(OOP_Object
*obj
, uint8_t type
, uint8_t index
, uint16_t length
, APTR descriptor
);
459 BOOL
HIDD_USBDevice_GetConfigDescriptor(OOP_Object
*obj
, uint8_t index
, usb_config_descriptor_t
*descriptor
);
460 BOOL
HIDD_USBDevice_GetDeviceDescriptor(OOP_Object
*obj
, usb_device_descriptor_t
*descriptor
);
461 BOOL
HIDD_USBDevice_GetStatus(OOP_Object
*obj
, usb_status_t
*status
);
462 APTR
HIDD_USBDevice_CreatePipe(OOP_Object
*obj
, enum USB_PipeType type
, uint8_t endpoint
, uint8_t period
, uint16_t maxpacket
, uint32_t timeout
);
463 void HIDD_USBDevice_DeletePipe(OOP_Object
*obj
, APTR pipe
);
464 BOOL
HIDD_USBDevice_GetString(OOP_Object
*obj
, int8_t id
, uint16_t language
, usb_string_descriptor_t
*string
);
465 BOOL
HIDD_USBDevice_ControlMessage(OOP_Object
*obj
, APTR pipe
, USBDevice_Request
*request
, APTR buffer
, uint32_t length
);
466 BOOL
HIDD_USBDevice_Configure(OOP_Object
*obj
, uint8_t configNr
);
467 usb_interface_descriptor_t
*HIDD_USBDevice_GetInterface(OOP_Object
*obj
, uint8_t interface
);
468 usb_endpoint_descriptor_t
*HIDD_USBDevice_GetEndpoint(OOP_Object
*obj
, uint8_t interface
, uint8_t endpoint
);
469 BOOL
HIDD_USBDevice_BulkTransfer(OOP_Object
*obj
, APTR pipe
, APTR buffer
, uint32_t length
);
470 void HIDD_USBDevice_SetTimeout(OOP_Object
*obj
, APTR pipe
, uint32_t timeout
);
472 BOOL
HIDD_USBHub_OnOff(OOP_Object
*obj
, BOOL on
);
473 OOP_Object
*HIDD_USBHub_GetChild(OOP_Object
*obj
, uint8_t port
);
474 BOOL
HIDD_USBHub_PortEnable(OOP_Object
*obj
, uint8_t port
, BOOL enable
);
475 BOOL
HIDD_USBHub_PortReset(OOP_Object
*obj
, uint8_t port
);
476 BOOL
HIDD_USBHub_GetPortStatus(OOP_Object
*obj
, uint8_t port
, usb_port_status_t
*status
);
477 BOOL
HIDD_USBHub_GetHubStatus(OOP_Object
*obj
, usb_hub_status_t
*status
);
478 BOOL
HIDD_USBHub_ClearHubFeature(OOP_Object
*obj
, int feature
);
479 BOOL
HIDD_USBHub_SetHubFeature(OOP_Object
*obj
, int feature
);
480 BOOL
HIDD_USBHub_ClearPortFeature(OOP_Object
*obj
, uint8_t port
, int feature
);
481 BOOL
HIDD_USBHub_SetPortFeature(OOP_Object
*obj
, uint8_t port
, int feature
);
482 BOOL
HIDD_USBHub_GetHubDescriptor(OOP_Object
*obj
, usb_hub_descriptor_t
*descriptor
);
484 APTR
HIDD_USBDrv_CreatePipe(OOP_Object
*obj
, enum USB_PipeType type
, BOOL fullspeed
, uint8_t address
, uint8_t endpoint
, uint8_t period
, uint32_t maxpacket
, uint32_t timeout
);
485 void HIDD_USBDrv_DeletePipe(OOP_Object
*obj
, APTR pipe
);
486 BOOL
HIDD_USBDrv_ControlTransfer(OOP_Object
*obj
, APTR pipe
, USBDevice_Request
*request
, APTR buffer
, uint32_t length
);
487 BOOL
HIDD_USBDrv_AddInterrupt(OOP_Object
*obj
, void *pipe
, void *buffer
, uint8_t length
, struct Interrupt
*interrupt
);
488 BOOL
HIDD_USBDrv_RemInterrupt(OOP_Object
*obj
, void *pipe
, struct Interrupt
*interrupt
);
489 BOOL
HIDD_USBDrv_BulkTransfer(OOP_Object
*obj
, APTR pipe
, APTR buffer
, uint32_t length
);
490 void HIDD_USBDrv_SetTimeout(OOP_Object
*obj
, APTR pipe
, uint32_t timeout
);