xref: /haiku/src/add-ons/kernel/drivers/input/usb_hid/HIDDevice.h (revision 746cac055adc6ac3308c7bc2d29040fb95689cc9)
1 /*
2 	Driver for USB Human Interface Devices.
3 	Copyright (C) 2008 Michael Lotz <mmlr@mlotz.ch>
4 	Distributed under the terms of the MIT license.
5 */
6 #ifndef _USB_HID_DEVICE_H_
7 #define _USB_HID_DEVICE_H_
8 
9 #include "hidparse.h"
10 #include "ring_buffer.h"
11 #include <USB3.h>
12 
13 class HIDDevice {
14 public:
15 								HIDDevice(usb_device device,
16 									usb_pipe interruptPipe,
17 									size_t interfaceIndex,
18 									report_insn *instructions,
19 									size_t instructionCount,
20 									size_t totalReportSize,
21 									size_t ringBufferSize);
22 virtual							~HIDDevice();
23 
24 static	HIDDevice *				MakeHIDDevice(usb_device device,
25 									const usb_configuration_info *config,
26 									size_t interfaceIndex);
27 
28 		void					SetBaseName(const char *baseName);
29 		const char *			Name() { return fName; };
30 
31 		void					SetParentCookie(int32 cookie);
32 		int32					ParentCookie() { return fParentCookie; };
33 
34 		status_t				InitCheck() { return fStatus; };
35 
36 virtual	status_t				Open(uint32 flags);
37 		bool					IsOpen() { return fOpen; };
38 
39 virtual	status_t				Close();
40 virtual	status_t				Free();
41 
42 virtual	status_t				Read(uint8 *buffer, size_t *numBytes);
43 virtual	status_t				Write(const uint8 *buffer, size_t *numBytes);
44 virtual	status_t				Control(uint32 op, void *buffer, size_t length);
45 
46 virtual	void					Removed();
47 		bool					IsRemoved() { return fRemoved; };
48 
49 protected:
50 		void					_SetTransferProcessed();
51 		bool					_IsTransferUnprocessed();
52 		status_t				_ScheduleTransfer();
53 
54 		int32					_RingBufferReadable();
55 		status_t				_RingBufferRead(void *buffer, size_t length);
56 		status_t				_RingBufferWrite(const void *buffer,
57 									size_t length);
58 
59 		status_t				fStatus;
60 		usb_device				fDevice;
61 		usb_pipe				fInterruptPipe;
62 		size_t					fInterfaceIndex;
63 		report_insn *			fInstructions;
64 		size_t					fInstructionCount;
65 		size_t					fTotalReportSize;
66 
67 		// transfer data
68 		bool					fTransferUnprocessed;
69 		status_t				fTransferStatus;
70 		size_t					fTransferActualLength;
71 		uint8 *					fTransferBuffer;
72 		sem_id					fTransferNotifySem;
73 
74 private:
75 static	void					_TransferCallback(void *cookie,
76 									status_t status, void *data,
77 									size_t actualLength);
78 
79 		char *					fName;
80 		int32					fParentCookie;
81 		bool					fOpen;
82 		bool					fRemoved;
83 
84 		struct ring_buffer *	fRingBuffer;
85 };
86 
87 #endif // _USB_HID_DEVICE_H_
88