gphoto2-port.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /** \file
  2. *
  3. * \author Copyright 2001 Lutz Mueller <lutz@users.sf.net>
  4. *
  5. * \par License
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * \par
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * \par
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA
  22. */
  23. #ifndef __GPHOTO2_PORT_H__
  24. #define __GPHOTO2_PORT_H__
  25. #include <gphoto2/gphoto2-port-info-list.h>
  26. /* For portability */
  27. #include <gphoto2/gphoto2-port-portability.h>
  28. #ifdef OS2
  29. #include <gphoto2/gphoto2-port-portability-os2.h>
  30. #include <os2.h>
  31. #endif
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif /* __cplusplus */
  35. #ifndef TRUE
  36. #define TRUE (0==0)
  37. #endif
  38. #ifndef FALSE
  39. #define FALSE (1==0)
  40. #endif
  41. /**
  42. * \brief Serial parity
  43. *
  44. * Parity of the serial port.
  45. */
  46. typedef enum _GPPortSerialParity
  47. {
  48. GP_PORT_SERIAL_PARITY_OFF = 0, /**< \brief Parity is off (disabled) */
  49. GP_PORT_SERIAL_PARITY_EVEN, /**< \brief Parity is even. */
  50. GP_PORT_SERIAL_PARITY_ODD /**< \brief Parity is odd. */
  51. } GPPortSerialParity;
  52. /** \brief Maximum length of receive buffer */
  53. #define GP_PORT_MAX_BUF_LEN 4096
  54. /**
  55. * \brief Port settings for serial ports.
  56. */
  57. typedef struct _GPPortSettingsSerial {
  58. char port[128]; /**< The portname (/dev/ttyX)*/
  59. int speed; /**< The baudrate of the device. */
  60. int bits; /**< How many bits data. */
  61. GPPortSerialParity parity; /**< parity data, see GP_PORT_SERIAL_PARITY_
  62. defines */
  63. int stopbits; /**< How many stop bits are used. */
  64. } GPPortSettingsSerial;
  65. /**
  66. * \brief Port settings for USB ports.
  67. */
  68. typedef struct _GPPortSettingsUSB {
  69. int inep; /**< \brief Bulk IN endpoint used. */
  70. int outep; /**< \brief Bulk OUT endpoint used. */
  71. int intep; /**< \brief Interrupt endpoint used. */
  72. int config; /**< \brief USB bConfigurationValue used. */
  73. int interface; /**< \brief USB Interface number used. */
  74. int altsetting; /**< \brief USB Alternative Setting used. */
  75. int maxpacketsize; /**< \brief Maximum USB packetsize of the IN endpoint. (r/o) */
  76. /* must be last to avoid binary incompatibility.
  77. * luckily we just need to make sure this struct does not
  78. * get larger than _GPPortSettingsSerial. */
  79. char port[64]; /**< \brief USB Portname. Specific to lowlevel USB. */
  80. } GPPortSettingsUSB;
  81. /**
  82. * \brief Port settings for USB mass storage direct IO ports.
  83. */
  84. typedef struct _GPPortSettingsUsbDiskDirect {
  85. char path[128]; /**< /brief The ports device node path (/dev/sdX)*/
  86. } GPPortSettingsUsbDiskDirect;
  87. /**
  88. * \brief Port settings for USB Mass Storage raw SCSI ports.
  89. */
  90. typedef struct _GPPortSettingsUsbScsi {
  91. char path[128]; /**< /brief The ports device node path (/dev/sg#)*/
  92. } GPPortSettingsUsbScsi;
  93. /**
  94. * \brief Union of port settings.
  95. *
  96. * This contains a shared union of possible settings for ports needing
  97. * them.
  98. */
  99. typedef union _GPPortSettings {
  100. GPPortSettingsSerial serial; /**< \brief Serial specific settings */
  101. GPPortSettingsUSB usb; /**< \brief USB specific settings */
  102. GPPortSettingsUsbDiskDirect usbdiskdirect; /**< \brief usb disk direct port specific settings */
  103. GPPortSettingsUsbScsi usbscsi; /**< \brief usb scsi port specific settings */
  104. } GPPortSettings;
  105. enum {
  106. GP_PORT_USB_ENDPOINT_IN, /**< \brief USB bulk IN ep */
  107. GP_PORT_USB_ENDPOINT_OUT, /**< \brief USB bulk OUT ep */
  108. GP_PORT_USB_ENDPOINT_INT /**< \brief USB Interrupt ep */
  109. };
  110. typedef struct _GPPortPrivateLibrary GPPortPrivateLibrary;
  111. typedef struct _GPPortPrivateCore GPPortPrivateCore;
  112. /**
  113. * \brief The GPhoto port structure.
  114. *
  115. * This structure tracks the physical connection of the device.
  116. * It can correspond the various methods of lowlevel access, serial
  117. * usb and others and abstracts them as much as possible.
  118. *
  119. * Frontends should consider this structure opaque and only use accessor
  120. * functions.
  121. *
  122. * Camera drivers should only access the type and pl members directly,
  123. * and use accessor functions for the rest.
  124. */
  125. typedef struct _GPPort {
  126. /* For your convenience */
  127. GPPortType type; /**< \brief Actual type of this port */
  128. GPPortSettings settings; /**< \brief Current port settings. */
  129. GPPortSettings settings_pending;/**< \brief Settings to be committed. */
  130. int timeout; /**< \brief Port timeout in milliseconds. */
  131. GPPortPrivateLibrary *pl; /**< \brief Camera driver private data pointer. */
  132. GPPortPrivateCore *pc; /**< \brief Port library private data pointer. */
  133. } GPPort;
  134. int gp_port_new (GPPort **port);
  135. int gp_port_free (GPPort *port);
  136. int gp_port_set_info (GPPort *port, GPPortInfo info);
  137. int gp_port_get_info (GPPort *port, GPPortInfo *info);
  138. int gp_port_open (GPPort *port);
  139. int gp_port_close (GPPort *port);
  140. int gp_port_reset (GPPort *port);
  141. int gp_port_write (GPPort *port, const char *data, int size);
  142. int gp_port_read (GPPort *port, char *data, int size);
  143. int gp_port_check_int (GPPort *port, char *data, int size);
  144. int gp_port_check_int_fast (GPPort *port, char *data, int size);
  145. int gp_port_get_timeout (GPPort *port, int *timeout);
  146. int gp_port_set_timeout (GPPort *port, int timeout);
  147. int gp_port_set_settings (GPPort *port, GPPortSettings settings);
  148. int gp_port_get_settings (GPPort *port, GPPortSettings *settings);
  149. /**
  150. * \brief Serial pins.
  151. *
  152. * A number of serial pins to trigger and pull. This is necessary
  153. * for some devices that have more than just the regular 3 or 4 wires.
  154. */
  155. typedef enum _GPPin {
  156. GP_PIN_RTS, /**< \brief RTS line */
  157. GP_PIN_DTR, /**< \brief DTR line */
  158. GP_PIN_CTS, /**< \brief CTS line */
  159. GP_PIN_DSR, /**< \brief DSR line */
  160. GP_PIN_CD, /**< \brief Carrier Detect line */
  161. GP_PIN_RING /**< \brief RING (Modem) line */
  162. } GPPin;
  163. /**
  164. * \brief Level to pull specific lines.
  165. *
  166. * The level on which to pull some of the serial lines.
  167. */
  168. typedef enum _GPLevel {
  169. GP_LEVEL_LOW = 0, /**< \brief Pull to low (0V) */
  170. GP_LEVEL_HIGH = 1 /**< \brief Pull to high (nV) */
  171. } GPLevel;
  172. int gp_port_get_pin (GPPort *port, GPPin pin, GPLevel *level);
  173. int gp_port_set_pin (GPPort *port, GPPin pin, GPLevel level);
  174. int gp_port_send_break (GPPort *port, int duration);
  175. int gp_port_flush (GPPort *port, int direction);
  176. int gp_port_usb_find_device (GPPort *port, int idvendor, int idproduct);
  177. int gp_port_usb_find_device_by_class (GPPort *port, int mainclass, int subclass, int protocol);
  178. int gp_port_usb_clear_halt (GPPort *port, int ep);
  179. int gp_port_usb_msg_write (GPPort *port, int request, int value,
  180. int index, char *bytes, int size);
  181. int gp_port_usb_msg_read (GPPort *port, int request, int value,
  182. int index, char *bytes, int size);
  183. int gp_port_usb_msg_interface_write (GPPort *port, int request,
  184. int value, int index, char *bytes, int size);
  185. int gp_port_usb_msg_interface_read (GPPort *port, int request,
  186. int value, int index, char *bytes, int size);
  187. int gp_port_usb_msg_class_write (GPPort *port, int request,
  188. int value, int index, char *bytes, int size);
  189. int gp_port_usb_msg_class_read (GPPort *port, int request,
  190. int value, int index, char *bytes, int size);
  191. int gp_port_seek (GPPort *port, int offset, int whence);
  192. int gp_port_send_scsi_cmd (GPPort *port, int to_dev,
  193. char *cmd, int cmd_size,
  194. char *sense, int sense_size,
  195. char *data, int data_size);
  196. /* Error reporting */
  197. int gp_port_set_error (GPPort *port, const char *format, ...)
  198. #ifdef __GNUC__
  199. __attribute__((__format__(printf,2,3)))
  200. #endif
  201. ;
  202. const char *gp_port_get_error (GPPort *port);
  203. /* DEPRECATED */
  204. /** \deprecated internal typedef */
  205. typedef GPPort gp_port;
  206. /** \deprecated internal typedef */
  207. typedef GPPortSettings gp_port_settings;
  208. /** \deprecated internal define */
  209. #define PIN_CTS GP_PIN_CTS
  210. #ifdef __cplusplus
  211. }
  212. #endif /* __cplusplus */
  213. #endif /* __GPHOTO2_PORT_H__ */