1 #ifndef __HID_WIIMOTE_H
2 #define __HID_WIIMOTE_H
5 * HID driver for Nintendo Wiimote devices
6 * Copyright (c) 2011 David Herrmann
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
16 #include <linux/completion.h>
17 #include <linux/device.h>
18 #include <linux/hid.h>
19 #include <linux/input.h>
20 #include <linux/leds.h>
21 #include <linux/module.h>
22 #include <linux/mutex.h>
23 #include <linux/power_supply.h>
24 #include <linux/spinlock.h>
26 #define WIIMOTE_NAME "Nintendo Wii Remote"
27 #define WIIMOTE_BUFSIZE 32
29 #define WIIPROTO_FLAG_LED1 0x01
30 #define WIIPROTO_FLAG_LED2 0x02
31 #define WIIPROTO_FLAG_LED3 0x04
32 #define WIIPROTO_FLAG_LED4 0x08
33 #define WIIPROTO_FLAG_RUMBLE 0x10
34 #define WIIPROTO_FLAG_ACCEL 0x20
35 #define WIIPROTO_FLAG_IR_BASIC 0x40
36 #define WIIPROTO_FLAG_IR_EXT 0x80
37 #define WIIPROTO_FLAG_IR_FULL 0xc0 /* IR_BASIC | IR_EXT */
38 #define WIIPROTO_FLAGS_LEDS (WIIPROTO_FLAG_LED1 | WIIPROTO_FLAG_LED2 | \
39 WIIPROTO_FLAG_LED3 | WIIPROTO_FLAG_LED4)
40 #define WIIPROTO_FLAGS_IR (WIIPROTO_FLAG_IR_BASIC | WIIPROTO_FLAG_IR_EXT | \
41 WIIPROTO_FLAG_IR_FULL)
43 /* return flag for led \num */
44 #define WIIPROTO_FLAG_LED(num) (WIIPROTO_FLAG_LED1 << (num - 1))
47 __u8 data
[HID_MAX_BUFFER_SIZE
];
51 struct wiimote_state
{
56 /* synchronous cmd requests */
58 struct completion ready
;
62 /* results of synchronous requests */
70 struct hid_device
*hdev
;
71 struct input_dev
*input
;
72 struct led_classdev
*leds
[4];
73 struct input_dev
*accel
;
75 struct power_supply battery
;
76 struct wiimote_ext
*ext
;
81 struct wiimote_buf outq
[WIIMOTE_BUFSIZE
];
82 struct work_struct worker
;
84 struct wiimote_state state
;
88 WIIPROTO_REQ_NULL
= 0x0,
89 WIIPROTO_REQ_RUMBLE
= 0x10,
90 WIIPROTO_REQ_LED
= 0x11,
91 WIIPROTO_REQ_DRM
= 0x12,
92 WIIPROTO_REQ_IR1
= 0x13,
93 WIIPROTO_REQ_SREQ
= 0x15,
94 WIIPROTO_REQ_WMEM
= 0x16,
95 WIIPROTO_REQ_RMEM
= 0x17,
96 WIIPROTO_REQ_IR2
= 0x1a,
97 WIIPROTO_REQ_STATUS
= 0x20,
98 WIIPROTO_REQ_DATA
= 0x21,
99 WIIPROTO_REQ_RETURN
= 0x22,
100 WIIPROTO_REQ_DRM_K
= 0x30,
101 WIIPROTO_REQ_DRM_KA
= 0x31,
102 WIIPROTO_REQ_DRM_KE
= 0x32,
103 WIIPROTO_REQ_DRM_KAI
= 0x33,
104 WIIPROTO_REQ_DRM_KEE
= 0x34,
105 WIIPROTO_REQ_DRM_KAE
= 0x35,
106 WIIPROTO_REQ_DRM_KIE
= 0x36,
107 WIIPROTO_REQ_DRM_KAIE
= 0x37,
108 WIIPROTO_REQ_DRM_E
= 0x3d,
109 WIIPROTO_REQ_DRM_SKAI1
= 0x3e,
110 WIIPROTO_REQ_DRM_SKAI2
= 0x3f,
113 #define dev_to_wii(pdev) hid_get_drvdata(container_of(pdev, struct hid_device, \
116 extern void wiiproto_req_drm(struct wiimote_data
*wdata
, __u8 drm
);
117 extern int wiimote_cmd_write(struct wiimote_data
*wdata
, __u32 offset
,
118 const __u8
*wmem
, __u8 size
);
119 extern ssize_t
wiimote_cmd_read(struct wiimote_data
*wdata
, __u32 offset
,
120 __u8
*rmem
, __u8 size
);
122 #ifdef CONFIG_HID_WIIMOTE_EXT
124 extern int wiiext_init(struct wiimote_data
*wdata
);
125 extern void wiiext_deinit(struct wiimote_data
*wdata
);
126 extern void wiiext_event(struct wiimote_data
*wdata
, bool plugged
);
127 extern bool wiiext_active(struct wiimote_data
*wdata
);
131 static inline int wiiext_init(void *u
) { return 0; }
132 static inline void wiiext_deinit(void *u
) { }
133 static inline void wiiext_event(void *u
, bool p
) { }
134 static inline bool wiiext_active(void *u
) { return false; }
138 /* requires the state.lock spinlock to be held */
139 static inline bool wiimote_cmd_pending(struct wiimote_data
*wdata
, int cmd
,
142 return wdata
->state
.cmd
== cmd
&& wdata
->state
.opt
== opt
;
145 /* requires the state.lock spinlock to be held */
146 static inline void wiimote_cmd_complete(struct wiimote_data
*wdata
)
148 wdata
->state
.cmd
= WIIPROTO_REQ_NULL
;
149 complete(&wdata
->state
.ready
);
152 static inline int wiimote_cmd_acquire(struct wiimote_data
*wdata
)
154 return mutex_lock_interruptible(&wdata
->state
.sync
) ? -ERESTARTSYS
: 0;
157 /* requires the state.lock spinlock to be held */
158 static inline void wiimote_cmd_set(struct wiimote_data
*wdata
, int cmd
,
161 INIT_COMPLETION(wdata
->state
.ready
);
162 wdata
->state
.cmd
= cmd
;
163 wdata
->state
.opt
= opt
;
166 static inline void wiimote_cmd_release(struct wiimote_data
*wdata
)
168 mutex_unlock(&wdata
->state
.sync
);
171 static inline int wiimote_cmd_wait(struct wiimote_data
*wdata
)
175 ret
= wait_for_completion_interruptible_timeout(&wdata
->state
.ready
, HZ
);
This page took 0.035028 seconds and 6 git commands to generate.