From 02a7c326c7747927e04c74a44240e0a8e0d0f637 Mon Sep 17 00:00:00 2001 From: Nirenjan Krishnan Date: Sun, 30 Sep 2012 14:28:51 -0700 Subject: [PATCH] Update x52 driver with write to MFD code. This still has a bug in that the text is not written correctly. It shows up as garbage. For now, I'm committing it so that I can work on it later after the brightness configuration is set up. Also add the commands header file. --- driver/x52joy.c | 73 +++++++++++++++++++++++++++++++++++++--- driver/x52joy_commands.h | 53 +++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 driver/x52joy_commands.h diff --git a/driver/x52joy.c b/driver/x52joy.c index a4fa7aa..4edebf4 100644 --- a/driver/x52joy.c +++ b/driver/x52joy.c @@ -20,6 +20,8 @@ #include #include +#include "x52joy_commands.h" + #define DRIVER_AUTHOR "Nirenjan Krishnan, nirenjan@gmail.com" #define DRIVER_DESC "Saitek X52Pro HOTAS Driver" @@ -45,7 +47,8 @@ MODULE_DEVICE_TABLE (usb, id_table); * - Date with YYMMDD (IIRC) */ #define DRIVER_LINE_SIZE 256 /* Support upto 256 bytes in the driver */ -#define X52_MFD_LINE_SIZE 17 /* Add one for null byte */ +#define X52_MFD_LINE_SIZE 16 +#define X52_MFD_LINES 3 struct x52_mfd_line { u8 text[DRIVER_LINE_SIZE]; @@ -56,7 +59,7 @@ struct x52_mfd_line { struct x52_joy { struct usb_device *udev; u32 led_status; - struct x52_mfd_line line[3]; + struct x52_mfd_line line[X52_MFD_LINES]; u8 time_hour; u8 time_min; u16 time_offs2; @@ -74,9 +77,65 @@ struct x52_joy { /********************************************************************** * MFD Line manipulation functions *********************************************************************/ -static void set_text(u8 line_no) +static const u8 line_cmd[X52_MFD_LINES] = { + X52_MFD_LINE1, + X52_MFD_LINE2, + X52_MFD_LINE3, +}; + +static void set_text(struct x52_joy *joy, u8 line_no) { - /* TODO */ + u16 i; + u16 pos; + u16 ch; + u16 length; + char *text_ptr; + int retval; + + if (!joy || line_no >= X52_MFD_LINES) { + /* Just some sanity checking */ + return; + } + + /* Clear the line first */ + retval = usb_control_msg(joy->udev, + usb_sndctrlpipe(joy->udev, 0), + X52_VENDOR_REQUEST, + USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, + 0x00, + line_cmd[line_no] | X52_MFD_CLEAR_LINE, + NULL, 0, 1000); + if (retval) { + return; + } + pos = joy->line[line_no].current_pos; + length = joy->line[line_no].length; + + for (i = 0; i < X52_MFD_LINE_SIZE; i+= 2) { + text_ptr = &joy->line[line_no].text[pos]; + if (length - pos > 1) { + ch = (u16 *)text_ptr; + } else { + ch = (*text_ptr) + (0x20 << 8); + } + + retval = usb_control_msg(joy->udev, + usb_sndctrlpipe(joy->udev, 0), + X52_VENDOR_REQUEST, + USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, + ch, + line_cmd[line_no] | X52_MFD_WRITE_LINE, + NULL, 0, 1000); + + pos += 2; + + if (pos >= length) { + pos = 0; + break; + } + } + + joy->line[line_no].current_pos = pos; return; } @@ -85,6 +144,8 @@ static ssize_t show_text_line(struct device *dev, char *buf, u8 line) struct usb_interface *intf = to_usb_interface(dev); struct x52_joy *joy = usb_get_intfdata(intf); + line--; /* Convert to 0-based line number */ + if (joy->feat_mfd) { return sprintf(buf, "%s\n", joy->line[line].text); } else { @@ -105,6 +166,8 @@ static ssize_t set_text_line(struct device *dev, const char *buf,\ if (!joy->feat_mfd) { return -EOPNOTSUPP; } + + line--; /* Convert to 0-based line number */ /* Copy the string from src to dst, upto 16 characters max */ for (i = 0, length = 0; i < DRIVER_LINE_SIZE - 1 && i < count; i++, length++) { @@ -118,7 +181,7 @@ static ssize_t set_text_line(struct device *dev, const char *buf,\ /* The X52 pro MFD uses space characters as empty characters */ joy->line[line].text[i] = 32; } - set_text(line); + set_text(joy, line); return count; } diff --git a/driver/x52joy_commands.h b/driver/x52joy_commands.h new file mode 100644 index 0000000..bb8a6c8 --- /dev/null +++ b/driver/x52joy_commands.h @@ -0,0 +1,53 @@ +/* + * Saitek X52 Pro HOTAS driver + * + * Copyright (C) 2012 Nirenjan Krishnan (nirenjan@nirenjan.org) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + * + */ + +#ifndef X52JOY_COMMANDS_H +#define X52JOY_COMMANDS_H + +/* X52 vendor API commands */ +/* Vendor request - all commands must have this request ID */ +#define X52_VENDOR_REQUEST 0x91 + +/* MFD Text commands */ +#define X52_MFD_CLEAR_LINE 0x08 +#define X52_MFD_WRITE_LINE 0x00 + +#define X52_MFD_LINE1 0xd1 +#define X52_MFD_LINE2 0xd2 +#define X52_MFD_LINE3 0xd4 + +/* Brightness commands */ +#define X52_MFD_BRIGHTNESS 0xb1 +#define X52_LED_BRIGHTNESS 0xb2 + +/* LED set commands */ +#define X52_LED 0xb8 + +/* Time commands */ +#define X52_TIME_CLOCK1 0xc0 +#define X52_OFFS_CLOCK2 0xc1 +#define X52_OFFS_CLOCK3 0xc2 + +/* Date commands */ +#define X52_DATE_DDMM 0xc4 +#define X52_DATE_YEAR 0xc8 + +/* Shift indicator on MFD */ +#define X52_SHIFT_INDICATOR 0xfd +#define X52_SHIFT_ON 0x51 +#define X52_SHIFT_OFF 0x50 + +/* Blink throttle & POV LED */ +#define X52_BLINK_INDICATOR 0xb4 +#define X52_BLINK_ON 0x51 +#define X52_BLINK_OFF 0x50 + +#endif /* !defined X52JOY_COMMANDS_H */