|
|
|
@@ -25,47 +25,49 @@
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/hid.h>
|
|
|
|
#include <linux/hid.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "g29_usb.h"
|
|
|
|
|
|
|
|
|
|
|
|
MODULE_AUTHOR("LLP group 16");
|
|
|
|
MODULE_AUTHOR("LLP group 16");
|
|
|
|
MODULE_DESCRIPTION("Logitech G29 USB driver");
|
|
|
|
MODULE_DESCRIPTION("Logitech G29 USB driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
|
|
|
|
#define USB_VENDOR_ID_LOGITECH 0x046d
|
|
|
|
|
|
|
|
#define USB_DEVICE_ID_LOGITECH_G29 0xc24f
|
|
|
|
|
|
|
|
#define USB_DEVICE_ID_LOGITECH_G29_ALT 0xc260
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define G29_BTN_PLUS 0x00800000u
|
|
|
|
|
|
|
|
#define G29_BTN_MINUS 0x01000000u
|
|
|
|
|
|
|
|
#define G29_BTN_RED_CW 0x02000000u
|
|
|
|
|
|
|
|
#define G29_BTN_RED_CCW 0x04000000u
|
|
|
|
|
|
|
|
#define G29_BTN_RETURN 0x08000000u
|
|
|
|
|
|
|
|
#define G29_BTN_R1 0x00000100u
|
|
|
|
|
|
|
|
#define G29_BTN_L1 0x00000200u
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum g29_mode {
|
|
|
|
enum g29_mode {
|
|
|
|
G29_MODE_MEDIA = 0,
|
|
|
|
G29_MODE_MEDIA = 0,
|
|
|
|
|
|
|
|
G29_MODE_WASD = 1,
|
|
|
|
|
|
|
|
G29_MODE_MOUSE = 2,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int mode = G29_MODE_MEDIA;
|
|
|
|
static int mode = G29_MODE_MEDIA;
|
|
|
|
module_param(mode, int, 0444);
|
|
|
|
module_param(mode, int, 0644);
|
|
|
|
MODULE_PARM_DESC(mode, "Mapping mode (0=MEDIA)");
|
|
|
|
MODULE_PARM_DESC(mode, "Initial mode (0=MEDIA, 1=WASD, 2=MOUSE)");
|
|
|
|
|
|
|
|
|
|
|
|
struct g29_state {
|
|
|
|
/* Steering curve exponent (100 = linear, 200 = squared, 150 = ^1.5)
|
|
|
|
u32 buttons_le;
|
|
|
|
* Higher values reduce sensitivity at low steering angles.
|
|
|
|
u16 rot_le;
|
|
|
|
*/
|
|
|
|
u8 gas;
|
|
|
|
static int steer_curve = 200;
|
|
|
|
u8 brk;
|
|
|
|
module_param(steer_curve, int, 0644);
|
|
|
|
u8 clt;
|
|
|
|
MODULE_PARM_DESC(steer_curve, "Steering sensitivity curve (100=linear, 200=squared, default=200)");
|
|
|
|
u8 gr_x;
|
|
|
|
|
|
|
|
u8 gr_y;
|
|
|
|
|
|
|
|
u8 gr_z;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct g29_keymap_edge {
|
|
|
|
static int steer_deadzone = 10;
|
|
|
|
|
|
|
|
module_param(steer_deadzone, int, 0644);
|
|
|
|
|
|
|
|
MODULE_PARM_DESC(steer_deadzone, "Steering deadzone radius from center (default=10)");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int gas_curve = 100;
|
|
|
|
|
|
|
|
module_param(gas_curve, int, 0644);
|
|
|
|
|
|
|
|
MODULE_PARM_DESC(gas_curve, "Gas pedal sensitivity curve (100=linear, 200=squared, default=200)");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int clutch_curve = 100;
|
|
|
|
|
|
|
|
module_param(clutch_curve, int, 0644);
|
|
|
|
|
|
|
|
MODULE_PARM_DESC(clutch_curve, "Clutch pedal sensitivity curve (100=linear, 200=squared, default=200)");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define NORMALIZATION_PRECISION 1000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct g29_keymap {
|
|
|
|
u32 mask;
|
|
|
|
u32 mask;
|
|
|
|
unsigned short keycode;
|
|
|
|
unsigned short keycode;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const struct g29_keymap_edge g29_media_edge_map[] = {
|
|
|
|
static const struct g29_keymap media_mode_keymap[] = {
|
|
|
|
/* Red rotary = volume */
|
|
|
|
/* Red rotary = volume */
|
|
|
|
{ G29_BTN_RED_CW, KEY_VOLUMEUP },
|
|
|
|
{ G29_BTN_RED_CW, KEY_VOLUMEUP },
|
|
|
|
{ G29_BTN_RED_CCW, KEY_VOLUMEDOWN },
|
|
|
|
{ G29_BTN_RED_CCW, KEY_VOLUMEDOWN },
|
|
|
|
@@ -78,6 +80,13 @@ static const struct g29_keymap_edge g29_media_edge_map[] = {
|
|
|
|
{ G29_BTN_L1, KEY_PREVIOUSSONG },
|
|
|
|
{ G29_BTN_L1, KEY_PREVIOUSSONG },
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const struct g29_keymap mouse_mode_keymap[] = {
|
|
|
|
|
|
|
|
{ G29_BTN_X, BTN_LEFT },
|
|
|
|
|
|
|
|
{ G29_BTN_CIRCLE, BTN_RIGHT },
|
|
|
|
|
|
|
|
{ G29_BTN_TRIANGLE, BTN_MIDDLE },
|
|
|
|
|
|
|
|
{ G29_BTN_SQUARE, BTN_SIDE },
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct g29_dev {
|
|
|
|
struct g29_dev {
|
|
|
|
char name[128];
|
|
|
|
char name[128];
|
|
|
|
char phys[64];
|
|
|
|
char phys[64];
|
|
|
|
@@ -93,47 +102,311 @@ struct g29_dev {
|
|
|
|
int endpoint;
|
|
|
|
int endpoint;
|
|
|
|
|
|
|
|
|
|
|
|
struct timer_list steer_timer;
|
|
|
|
struct timer_list steer_timer;
|
|
|
|
|
|
|
|
struct timer_list mouse_timer;
|
|
|
|
u32 steer_phase_ms;
|
|
|
|
u32 steer_phase_ms;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
u32 phase_accumulator;
|
|
|
|
|
|
|
|
u32 gas_phase_accumulator;
|
|
|
|
|
|
|
|
u32 clutch_phase_accumulator;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum g29_mode current_mode;
|
|
|
|
struct g29_state last;
|
|
|
|
struct g29_state last;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void g29_steer_timer_fn(struct timer_list *t) {
|
|
|
|
|
|
|
|
|
|
|
|
static void g29_switch_mode(struct g29_dev *g29, enum g29_mode new_mode) {
|
|
|
|
|
|
|
|
if (g29->current_mode == new_mode)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Stop timers when leaving modes */
|
|
|
|
|
|
|
|
if (g29->current_mode == G29_MODE_WASD) {
|
|
|
|
|
|
|
|
timer_delete_sync(&g29->steer_timer);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g29->current_mode == G29_MODE_MOUSE) {
|
|
|
|
|
|
|
|
timer_delete_sync(&g29->mouse_timer);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g29->current_mode = new_mode;
|
|
|
|
|
|
|
|
g29->phase_accumulator = 0;
|
|
|
|
|
|
|
|
g29->gas_phase_accumulator = 0;
|
|
|
|
|
|
|
|
g29->clutch_phase_accumulator = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Start timers when entering modes */
|
|
|
|
|
|
|
|
if (new_mode == G29_MODE_WASD) {
|
|
|
|
|
|
|
|
mod_timer(&g29->steer_timer, jiffies + msecs_to_jiffies(2));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_mode == G29_MODE_MOUSE) {
|
|
|
|
|
|
|
|
mod_timer(&g29->mouse_timer, jiffies + msecs_to_jiffies(10));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dev_info(&g29->udev->dev, "Switched to mode: %s\n",
|
|
|
|
|
|
|
|
new_mode == G29_MODE_MEDIA ? "MEDIA" :
|
|
|
|
|
|
|
|
new_mode == G29_MODE_WASD ? "WASD" : "MOUSE");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int calc_adjusted_steering_distance(int distance) {
|
|
|
|
|
|
|
|
/* Apply non-linear steering curve:
|
|
|
|
|
|
|
|
* adjusted = (distance / MAX)^(curve/100) * MAX
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* For curve=200 (squared): 5% input -> 0.25% output, 50% -> 25%, 100% -> 100%
|
|
|
|
|
|
|
|
* For curve=150 (^1.5): 5% input -> ~1.1% output, 50% -> ~35%, 100% -> 100%
|
|
|
|
|
|
|
|
* For curve=100 (linear): 5% input -> 5% output (no change)
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Using integer math: adjusted = (distance^2 / MAX) for curve=200
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (steer_curve == 100) {
|
|
|
|
|
|
|
|
return distance;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (steer_curve == 200) {
|
|
|
|
|
|
|
|
return(distance * distance) / WHEEL_MAX_DIST;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Generic power curve using normalized values (0-1000 range for precision)
|
|
|
|
|
|
|
|
* normalized = (distance * 1000) / WHEEL_MAX_DIST
|
|
|
|
|
|
|
|
* Apply power approximation, then scale back
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int normalized = (distance * NORMALIZATION_PRECISION) / WHEEL_MAX_DIST;
|
|
|
|
|
|
|
|
int powered;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (steer_curve == 150) {
|
|
|
|
|
|
|
|
/* Approximate ^1.5 with (x * sqrt(x)) */
|
|
|
|
|
|
|
|
int sqrt_norm = int_sqrt(normalized * NORMALIZATION_PRECISION);
|
|
|
|
|
|
|
|
powered = (normalized * sqrt_norm) / NORMALIZATION_PRECISION;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* Fallback: squared for any other value > 100 */
|
|
|
|
|
|
|
|
powered = (normalized * normalized) / NORMALIZATION_PRECISION;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (powered * WHEEL_MAX_DIST) / NORMALIZATION_PRECISION;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int calc_adjusted_pedal_distance(int pedal_pressure, int curve) {
|
|
|
|
|
|
|
|
if (curve == 100) {
|
|
|
|
|
|
|
|
return pedal_pressure;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curve == 200) {
|
|
|
|
|
|
|
|
return (pedal_pressure * pedal_pressure) / G29_PEDAL_RELEASED;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int normalized = (pedal_pressure * NORMALIZATION_PRECISION) / G29_PEDAL_RELEASED;
|
|
|
|
|
|
|
|
int powered;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (curve == 150) {
|
|
|
|
|
|
|
|
int sqrt_norm = int_sqrt(normalized * NORMALIZATION_PRECISION);
|
|
|
|
|
|
|
|
powered = (normalized * sqrt_norm) / NORMALIZATION_PRECISION;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
powered = (normalized * normalized) / NORMALIZATION_PRECISION;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (powered * G29_PEDAL_RELEASED) / NORMALIZATION_PRECISION;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void mouse_mode_timer_fn(struct timer_list *t) {
|
|
|
|
|
|
|
|
struct g29_dev *g29 = timer_container_of(g29, t, mouse_timer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const int rot = le16_to_cpu(g29->last.rot_le);
|
|
|
|
|
|
|
|
int gas_pressure = G29_PEDAL_RELEASED - g29->last.gas;
|
|
|
|
|
|
|
|
int clutch_pressure = G29_PEDAL_RELEASED - g29->last.clt;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Calculate speed: positive for forward (gas), negative for backward (clutch) */
|
|
|
|
|
|
|
|
int speed = gas_pressure - clutch_pressure;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Apply deadzone to steering */
|
|
|
|
|
|
|
|
int effective_rot = rot;
|
|
|
|
|
|
|
|
if (abs(rot - WHEEL_CENTER) <= steer_deadzone) {
|
|
|
|
|
|
|
|
effective_rot = WHEEL_CENTER;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Calculate angle from wheel rotation
|
|
|
|
|
|
|
|
* Map wheel rotation to angle:
|
|
|
|
|
|
|
|
* - Center (32768) = 0° (straight forward)
|
|
|
|
|
|
|
|
* - Full left (0) = -180° (reverse)
|
|
|
|
|
|
|
|
* - Full right (65535) = +180° (reverse)
|
|
|
|
|
|
|
|
* We normalize to -1000 to +1000 representing -π to +π radians
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int angle_normalized = ((effective_rot - WHEEL_CENTER) * 1000) / WHEEL_CENTER;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Clamp angle to prevent overflow */
|
|
|
|
|
|
|
|
if (angle_normalized > 1000) angle_normalized = 1000;
|
|
|
|
|
|
|
|
if (angle_normalized < -1000) angle_normalized = -1000;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Calculate movement components using better trigonometric approximations:
|
|
|
|
|
|
|
|
* dx = sin(angle) * speed
|
|
|
|
|
|
|
|
* dy = cos(angle) * speed
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* sin(x) ≈ x - x³/6 (Taylor series)
|
|
|
|
|
|
|
|
* cos(x) ≈ 1 - x²/2 + x⁴/24 (Taylor series)
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* For angle_normalized in [-1000, 1000] representing [-π, +π]:
|
|
|
|
|
|
|
|
* This gives us full reverse when fully steered
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
long angle_cubed = ((long)angle_normalized * angle_normalized * angle_normalized) / 1000000;
|
|
|
|
|
|
|
|
int sin_approx = (angle_normalized * 1000 - angle_cubed / 6) / 1000;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long angle_squared = ((long)angle_normalized * angle_normalized) / 1000;
|
|
|
|
|
|
|
|
long angle_fourth = (angle_squared * angle_squared) / 1000;
|
|
|
|
|
|
|
|
int cos_approx = 1000 - angle_squared / 2 + angle_fourth / 24;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int dx = (sin_approx * speed) / 1000;
|
|
|
|
|
|
|
|
int dy = -(cos_approx * speed) / 1000; /* Negative because forward is -Y */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Scale down the movement for reasonable mouse speed */
|
|
|
|
|
|
|
|
int scaled_dx = dx / 50;
|
|
|
|
|
|
|
|
int scaled_dy = dy / 50;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Report mouse movement if there's any */
|
|
|
|
|
|
|
|
if (scaled_dx != 0 || scaled_dy != 0) {
|
|
|
|
|
|
|
|
input_report_rel(g29->input, REL_X, scaled_dx);
|
|
|
|
|
|
|
|
input_report_rel(g29->input, REL_Y, scaled_dy);
|
|
|
|
|
|
|
|
input_sync(g29->input);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Reschedule timer if still in mouse mode */
|
|
|
|
|
|
|
|
if (g29->current_mode == G29_MODE_MOUSE)
|
|
|
|
|
|
|
|
mod_timer(&g29->mouse_timer, jiffies + msecs_to_jiffies(10));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wasd_mode_timer_fn(struct timer_list *t) {
|
|
|
|
struct g29_dev *g29 = timer_container_of(g29, t, steer_timer);
|
|
|
|
struct g29_dev *g29 = timer_container_of(g29, t, steer_timer);
|
|
|
|
|
|
|
|
|
|
|
|
const int rot = le16_to_cpu(g29->last.rot_le);
|
|
|
|
const int rot = le16_to_cpu(g29->last.rot_le);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int effective_rot = rot;
|
|
|
|
|
|
|
|
int distance_from_center = abs(rot - WHEEL_CENTER);
|
|
|
|
|
|
|
|
if (distance_from_center <= steer_deadzone) {
|
|
|
|
|
|
|
|
effective_rot = WHEEL_CENTER;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int distance_to_center = abs(effective_rot - WHEEL_CENTER);
|
|
|
|
|
|
|
|
int adjusted_distance = calc_adjusted_steering_distance(distance_to_center);
|
|
|
|
|
|
|
|
|
|
|
|
input_report_key(g29->input, KEY_W, g29->last.gas <= 0x80);
|
|
|
|
/* Phase accumulator approach:
|
|
|
|
input_report_key(g29->input, KEY_S, g29->last.clt <= 0x80);
|
|
|
|
* Accumulate the adjusted distance on each tick.
|
|
|
|
input_report_key(g29->input, KEY_A, rot <= 0x6000);
|
|
|
|
* When it exceeds the max distance, press the key and wrap.
|
|
|
|
input_report_key(g29->input, KEY_D, rot >= 0xA000);
|
|
|
|
* This gives us a duty cycle of (adjusted_distance / WHEEL_MAX_DIST).
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Examples (with curve=200):
|
|
|
|
|
|
|
|
* 5% steering -> ~0.25% press rate
|
|
|
|
|
|
|
|
* 50% steering -> 25% press rate
|
|
|
|
|
|
|
|
* 100% steering -> 100% press rate (every tick)
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
g29->phase_accumulator += adjusted_distance;
|
|
|
|
|
|
|
|
|
|
|
|
mod_timer(&g29->steer_timer, jiffies + msecs_to_jiffies(2));
|
|
|
|
bool press_key;
|
|
|
|
|
|
|
|
if (g29->phase_accumulator >= WHEEL_MAX_DIST) {
|
|
|
|
|
|
|
|
g29->phase_accumulator -= WHEEL_MAX_DIST;
|
|
|
|
|
|
|
|
press_key = true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
press_key = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
input_report_key(g29->input, KEY_A, press_key && (effective_rot < WHEEL_CENTER));
|
|
|
|
|
|
|
|
input_report_key(g29->input, KEY_D, press_key && (effective_rot >= WHEEL_CENTER));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Gas pedal (0xFF=up, 0x00=down) -> W key */
|
|
|
|
|
|
|
|
int gas_pressure = 0xFF - g29->last.gas;
|
|
|
|
|
|
|
|
int gas_adjusted = calc_adjusted_pedal_distance(gas_pressure, gas_curve);
|
|
|
|
|
|
|
|
g29->gas_phase_accumulator += gas_adjusted;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool press_w = false;
|
|
|
|
|
|
|
|
if (g29->gas_phase_accumulator >= G29_PEDAL_RELEASED) {
|
|
|
|
|
|
|
|
g29->gas_phase_accumulator -= G29_PEDAL_RELEASED;
|
|
|
|
|
|
|
|
press_w = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Clutch pedal (0xFF=up, 0x00=down) -> S key */
|
|
|
|
|
|
|
|
int clutch_pressure = 0xFF - g29->last.clt;
|
|
|
|
|
|
|
|
int clutch_adjusted = calc_adjusted_pedal_distance(clutch_pressure, clutch_curve);
|
|
|
|
|
|
|
|
g29->clutch_phase_accumulator += clutch_adjusted;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool press_s = false;
|
|
|
|
|
|
|
|
if (g29->clutch_phase_accumulator >= G29_PEDAL_RELEASED) {
|
|
|
|
|
|
|
|
g29->clutch_phase_accumulator -= G29_PEDAL_RELEASED;
|
|
|
|
|
|
|
|
press_s = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
input_report_key(g29->input, KEY_W, press_w);
|
|
|
|
|
|
|
|
input_report_key(g29->input, KEY_S, press_s);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
input_sync(g29->input);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (g29->current_mode == G29_MODE_WASD)
|
|
|
|
|
|
|
|
mod_timer(&g29->steer_timer, jiffies + msecs_to_jiffies(2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void g29_apply_media_mode(struct g29_dev *g29, const struct g29_state *cur, const struct g29_state *prev) {
|
|
|
|
static void process_media_mode(struct g29_dev *g29, const struct g29_state *cur, const struct g29_state *prev) {
|
|
|
|
u32 pressed = le32_to_cpu(cur->buttons_le & ~prev->buttons_le);
|
|
|
|
const u32 pressed = le32_to_cpu(cur->buttons_le & ~prev->buttons_le);
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(g29_media_edge_map); i++) {
|
|
|
|
const u32 released = le32_to_cpu(~cur->buttons_le & prev->buttons_le);
|
|
|
|
const struct g29_keymap_edge *e = &g29_media_edge_map[i];
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(media_mode_keymap); i++) {
|
|
|
|
if (pressed & e->mask) {
|
|
|
|
const struct g29_keymap *k = &media_mode_keymap[i];
|
|
|
|
input_report_key(g29->input, e->keycode, 1);
|
|
|
|
if (pressed & k->mask) {
|
|
|
|
input_report_key(g29->input, e->keycode, 0);
|
|
|
|
input_report_key(g29->input, k->keycode, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (released & k->mask) {
|
|
|
|
|
|
|
|
input_report_key(g29->input, k->keycode, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
input_sync(g29->input);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void process_wasd_mode(struct g29_dev *g29, const struct g29_state *cur, const struct g29_state *prev) {
|
|
|
|
|
|
|
|
/* WASD mode is handled by the timer function (g29_steer_timer_fn) */
|
|
|
|
|
|
|
|
/* No additional processing needed here */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void process_mouse_mode(struct g29_dev *g29, const struct g29_state *cur, const struct g29_state *prev) {
|
|
|
|
|
|
|
|
const u32 pressed = le32_to_cpu(cur->buttons_le & ~prev->buttons_le);
|
|
|
|
|
|
|
|
const u32 released = le32_to_cpu(~cur->buttons_le & prev->buttons_le);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(mouse_mode_keymap); i++) {
|
|
|
|
|
|
|
|
const struct g29_keymap *k = &mouse_mode_keymap[i];
|
|
|
|
|
|
|
|
if (pressed & k->mask) {
|
|
|
|
|
|
|
|
input_report_key(g29->input, k->keycode, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (released & k->mask) {
|
|
|
|
|
|
|
|
input_report_key(g29->input, k->keycode, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pressed & G29_BTN_RED_CW) {
|
|
|
|
|
|
|
|
input_report_rel(g29->input, REL_WHEEL, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pressed & G29_BTN_RED_CCW) {
|
|
|
|
|
|
|
|
input_report_rel(g29->input, REL_WHEEL, -1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
input_sync(g29->input);
|
|
|
|
input_sync(g29->input);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void g29_check_mode_switch(struct g29_dev *g29, const struct g29_state *cur, const struct g29_state *prev) {
|
|
|
|
|
|
|
|
u32 pressed = le32_to_cpu(cur->buttons_le & ~prev->buttons_le);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pressed & G29_BTN_SHARE) {
|
|
|
|
|
|
|
|
g29_switch_mode(g29, G29_MODE_MEDIA);
|
|
|
|
|
|
|
|
} else if (pressed & G29_BTN_OPTION) {
|
|
|
|
|
|
|
|
g29_switch_mode(g29, G29_MODE_WASD);
|
|
|
|
|
|
|
|
} else if (pressed & G29_BTN_PS3_LOGO) {
|
|
|
|
|
|
|
|
g29_switch_mode(g29, G29_MODE_MOUSE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void g29_process_report(struct g29_dev *g29, const u8 *data, unsigned int len) {
|
|
|
|
static void g29_process_report(struct g29_dev *g29, const u8 *data, unsigned int len) {
|
|
|
|
if (len < 12) return;
|
|
|
|
if (len < 12) return;
|
|
|
|
|
|
|
|
|
|
|
|
struct g29_state *cur = (void *) data;
|
|
|
|
struct g29_state *cur = (void *) data;
|
|
|
|
switch (mode) {
|
|
|
|
|
|
|
|
case G29_MODE_MEDIA:
|
|
|
|
g29_check_mode_switch(g29, cur, &g29->last);
|
|
|
|
default:
|
|
|
|
|
|
|
|
g29_apply_media_mode(g29, cur, &g29->last);
|
|
|
|
switch (g29->current_mode) {
|
|
|
|
break;
|
|
|
|
case G29_MODE_MEDIA:
|
|
|
|
|
|
|
|
process_media_mode(g29, cur, &g29->last);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G29_MODE_WASD:
|
|
|
|
|
|
|
|
process_wasd_mode(g29, cur, &g29->last);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G29_MODE_MOUSE:
|
|
|
|
|
|
|
|
process_mouse_mode(g29, cur, &g29->last);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
g29->last = *cur;
|
|
|
|
g29->last = *cur;
|
|
|
|
@@ -169,14 +442,19 @@ static int g29_input_open(struct input_dev *input) {
|
|
|
|
if (usb_submit_urb(g29->urb, GFP_KERNEL))
|
|
|
|
if (usb_submit_urb(g29->urb, GFP_KERNEL))
|
|
|
|
return -EIO;
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
|
|
|
|
mod_timer(&g29->steer_timer, jiffies + msecs_to_jiffies(2));
|
|
|
|
g29_switch_mode(g29, mode);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void g29_input_close(struct input_dev *input) {
|
|
|
|
static void g29_input_close(struct input_dev *input) {
|
|
|
|
struct g29_dev *g29 = input_get_drvdata(input);
|
|
|
|
struct g29_dev *g29 = input_get_drvdata(input);
|
|
|
|
timer_delete_sync(&g29->steer_timer);
|
|
|
|
|
|
|
|
|
|
|
|
if (g29->current_mode == G29_MODE_WASD)
|
|
|
|
|
|
|
|
timer_delete_sync(&g29->steer_timer);
|
|
|
|
|
|
|
|
if (g29->current_mode == G29_MODE_MOUSE)
|
|
|
|
|
|
|
|
timer_delete_sync(&g29->mouse_timer);
|
|
|
|
|
|
|
|
|
|
|
|
usb_kill_urb(g29->urb);
|
|
|
|
usb_kill_urb(g29->urb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -216,8 +494,10 @@ static int g29_probe(struct usb_interface *intf, const struct usb_device_id *id)
|
|
|
|
g29->maxp = usb_endpoint_maxp(ep);
|
|
|
|
g29->maxp = usb_endpoint_maxp(ep);
|
|
|
|
g29->interval = ep->bInterval;
|
|
|
|
g29->interval = ep->bInterval;
|
|
|
|
memset(&g29->last, 0, sizeof(g29->last));
|
|
|
|
memset(&g29->last, 0, sizeof(g29->last));
|
|
|
|
|
|
|
|
g29->current_mode = mode; /* Initialize to module parameter */
|
|
|
|
|
|
|
|
|
|
|
|
timer_setup(&g29->steer_timer, g29_steer_timer_fn, 0);
|
|
|
|
timer_setup(&g29->steer_timer, wasd_mode_timer_fn, 0);
|
|
|
|
|
|
|
|
timer_setup(&g29->mouse_timer, mouse_mode_timer_fn, 0);
|
|
|
|
|
|
|
|
|
|
|
|
if ((g29->buf = usb_alloc_coherent(udev, g29->maxp, GFP_KERNEL, &g29->buf_dma)) == NULL) {
|
|
|
|
if ((g29->buf = usb_alloc_coherent(udev, g29->maxp, GFP_KERNEL, &g29->buf_dma)) == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
ret = -ENOMEM;
|
|
|
|
@@ -251,19 +531,29 @@ static int g29_probe(struct usb_interface *intf, const struct usb_device_id *id)
|
|
|
|
input->dev.parent = &intf->dev;
|
|
|
|
input->dev.parent = &intf->dev;
|
|
|
|
|
|
|
|
|
|
|
|
__set_bit(EV_KEY, input->evbit);
|
|
|
|
__set_bit(EV_KEY, input->evbit);
|
|
|
|
|
|
|
|
__set_bit(EV_REL, input->evbit);
|
|
|
|
|
|
|
|
|
|
|
|
/* Advertise only the keys we emit in media mode. */
|
|
|
|
/* Media mode keys */
|
|
|
|
input_set_capability(input, EV_KEY, KEY_VOLUMEUP);
|
|
|
|
input_set_capability(input, EV_KEY, KEY_VOLUMEUP);
|
|
|
|
input_set_capability(input, EV_KEY, KEY_VOLUMEDOWN);
|
|
|
|
input_set_capability(input, EV_KEY, KEY_VOLUMEDOWN);
|
|
|
|
input_set_capability(input, EV_KEY, KEY_PLAYPAUSE);
|
|
|
|
input_set_capability(input, EV_KEY, KEY_PLAYPAUSE);
|
|
|
|
input_set_capability(input, EV_KEY, KEY_NEXTSONG);
|
|
|
|
input_set_capability(input, EV_KEY, KEY_NEXTSONG);
|
|
|
|
input_set_capability(input, EV_KEY, KEY_PREVIOUSSONG);
|
|
|
|
input_set_capability(input, EV_KEY, KEY_PREVIOUSSONG);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* WASD mode keys */
|
|
|
|
input_set_capability(input, EV_KEY, KEY_W);
|
|
|
|
input_set_capability(input, EV_KEY, KEY_W);
|
|
|
|
input_set_capability(input, EV_KEY, KEY_A);
|
|
|
|
input_set_capability(input, EV_KEY, KEY_A);
|
|
|
|
input_set_capability(input, EV_KEY, KEY_S);
|
|
|
|
input_set_capability(input, EV_KEY, KEY_S);
|
|
|
|
input_set_capability(input, EV_KEY, KEY_D);
|
|
|
|
input_set_capability(input, EV_KEY, KEY_D);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Mouse mode capabilities */
|
|
|
|
|
|
|
|
input_set_capability(input, EV_KEY, BTN_LEFT);
|
|
|
|
|
|
|
|
input_set_capability(input, EV_KEY, BTN_RIGHT);
|
|
|
|
|
|
|
|
input_set_capability(input, EV_KEY, BTN_MIDDLE);
|
|
|
|
|
|
|
|
input_set_capability(input, EV_REL, REL_X);
|
|
|
|
|
|
|
|
input_set_capability(input, EV_REL, REL_Y);
|
|
|
|
|
|
|
|
input_set_capability(input, EV_REL, REL_WHEEL);
|
|
|
|
|
|
|
|
|
|
|
|
input_set_drvdata(input, g29);
|
|
|
|
input_set_drvdata(input, g29);
|
|
|
|
input->open = g29_input_open;
|
|
|
|
input->open = g29_input_open;
|
|
|
|
input->close = g29_input_close;
|
|
|
|
input->close = g29_input_close;
|
|
|
|
|