iforce.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * $Id: iforce.h,v 1.13 2002/07/07 10:22:50 jdeneux Exp $
  3. *
  4. * Copyright (c) 2000-2002 Vojtech Pavlik <vojtech@ucw.cz>
  5. * Copyright (c) 2001-2002 Johann Deneux <deneux@ifrance.com>
  6. *
  7. * USB/RS232 I-Force joysticks and wheels.
  8. */
  9. /*
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. * Should you need to contact me, the author, you can do so either by
  25. * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
  26. * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
  27. */
  28. #include <linux/kernel.h>
  29. #include <linux/slab.h>
  30. #include <linux/input.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/spinlock.h>
  34. #include <linux/usb.h>
  35. #include <linux/serio.h>
  36. #include <linux/circ_buf.h>
  37. #include <linux/mutex.h>
  38. /* This module provides arbitrary resource management routines.
  39. * I use it to manage the device's memory.
  40. * Despite the name of this module, I am *not* going to access the ioports.
  41. */
  42. #include <linux/ioport.h>
  43. #define IFORCE_MAX_LENGTH 16
  44. /* iforce::bus */
  45. #define IFORCE_232 1
  46. #define IFORCE_USB 2
  47. #define IFORCE_EFFECTS_MAX 32
  48. /* Each force feedback effect is made of one core effect, which can be
  49. * associated to at most to effect modifiers
  50. */
  51. #define FF_MOD1_IS_USED 0
  52. #define FF_MOD2_IS_USED 1
  53. #define FF_CORE_IS_USED 2
  54. #define FF_CORE_IS_PLAYED 3 /* Effect is currently being played */
  55. #define FF_CORE_SHOULD_PLAY 4 /* User wants the effect to be played */
  56. #define FF_CORE_UPDATE 5 /* Effect is being updated */
  57. #define FF_MODCORE_MAX 5
  58. struct iforce_core_effect {
  59. /* Information about where modifiers are stored in the device's memory */
  60. struct resource mod1_chunk;
  61. struct resource mod2_chunk;
  62. unsigned long flags[NBITS(FF_MODCORE_MAX)];
  63. };
  64. #define FF_CMD_EFFECT 0x010e
  65. #define FF_CMD_ENVELOPE 0x0208
  66. #define FF_CMD_MAGNITUDE 0x0303
  67. #define FF_CMD_PERIOD 0x0407
  68. #define FF_CMD_CONDITION 0x050a
  69. #define FF_CMD_AUTOCENTER 0x4002
  70. #define FF_CMD_PLAY 0x4103
  71. #define FF_CMD_ENABLE 0x4201
  72. #define FF_CMD_GAIN 0x4301
  73. #define FF_CMD_QUERY 0xff01
  74. /* Buffer for async write */
  75. #define XMIT_SIZE 256
  76. #define XMIT_INC(var, n) (var)+=n; (var)&= XMIT_SIZE -1
  77. /* iforce::xmit_flags */
  78. #define IFORCE_XMIT_RUNNING 0
  79. #define IFORCE_XMIT_AGAIN 1
  80. struct iforce_device {
  81. u16 idvendor;
  82. u16 idproduct;
  83. char *name;
  84. signed short *btn;
  85. signed short *abs;
  86. signed short *ff;
  87. };
  88. struct iforce {
  89. struct input_dev *dev; /* Input device interface */
  90. struct iforce_device *type;
  91. int bus;
  92. unsigned char data[IFORCE_MAX_LENGTH];
  93. unsigned char edata[IFORCE_MAX_LENGTH];
  94. u16 ecmd;
  95. u16 expect_packet;
  96. #ifdef CONFIG_JOYSTICK_IFORCE_232
  97. struct serio *serio; /* RS232 transfer */
  98. int idx, pkt, len, id;
  99. unsigned char csum;
  100. #endif
  101. #ifdef CONFIG_JOYSTICK_IFORCE_USB
  102. struct usb_device *usbdev; /* USB transfer */
  103. struct urb *irq, *out, *ctrl;
  104. struct usb_ctrlrequest cr;
  105. #endif
  106. spinlock_t xmit_lock;
  107. /* Buffer used for asynchronous sending of bytes to the device */
  108. struct circ_buf xmit;
  109. unsigned char xmit_data[XMIT_SIZE];
  110. long xmit_flags[1];
  111. /* Force Feedback */
  112. wait_queue_head_t wait;
  113. struct resource device_memory;
  114. struct iforce_core_effect core_effects[IFORCE_EFFECTS_MAX];
  115. struct mutex mem_mutex;
  116. };
  117. /* Get hi and low bytes of a 16-bits int */
  118. #define HI(a) ((unsigned char)((a) >> 8))
  119. #define LO(a) ((unsigned char)((a) & 0xff))
  120. /* For many parameters, it seems that 0x80 is a special value that should
  121. * be avoided. Instead, we replace this value by 0x7f
  122. */
  123. #define HIFIX80(a) ((unsigned char)(((a)<0? (a)+255 : (a))>>8))
  124. /* Encode a time value */
  125. #define TIME_SCALE(a) (a)
  126. /* Public functions */
  127. /* iforce-serio.c */
  128. void iforce_serial_xmit(struct iforce *iforce);
  129. /* iforce-usb.c */
  130. void iforce_usb_xmit(struct iforce *iforce);
  131. void iforce_usb_delete(struct iforce *iforce);
  132. /* iforce-main.c */
  133. int iforce_init_device(struct iforce *iforce);
  134. void iforce_delete_device(struct iforce *iforce);
  135. /* iforce-packets.c */
  136. int iforce_control_playback(struct iforce*, u16 id, unsigned int);
  137. void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data);
  138. int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data);
  139. void iforce_dump_packet(char *msg, u16 cmd, unsigned char *data) ;
  140. int iforce_get_id_packet(struct iforce *iforce, char *packet);
  141. /* iforce-ff.c */
  142. int iforce_upload_periodic(struct iforce *, struct ff_effect *, struct ff_effect *);
  143. int iforce_upload_constant(struct iforce *, struct ff_effect *, struct ff_effect *);
  144. int iforce_upload_condition(struct iforce *, struct ff_effect *, struct ff_effect *);
  145. /* Public variables */
  146. extern struct serio_driver iforce_serio_drv;
  147. extern struct usb_driver iforce_usb_driver;