Added version attribute.
[libftdi] / bindings / ftdi1.i
CommitLineData
bcf4a08b 1/* File: ftdi1.i */
4c5afeb9 2
bcf4a08b 3%module(docstring="Python interface to libftdi1") ftdi1
31fba51d 4%feature("autodoc","1");
e15345ab 5
f9e62be7
DW
6#ifdef DOXYGEN
7%include "ftdi1_doc.i"
8#endif
4c5afeb9 9
abc3a514
MZ
10%{
11#include "Python.h"
12
3b96824e
MZ
13PyObject* convertString( const char *v, Py_ssize_t len )
14{
abc3a514 15#if PY_MAJOR_VERSION >= 3
3b96824e 16 return PyBytes_FromStringAndSize(v, len);
abc3a514 17#else
3b96824e 18 return PyString_FromStringAndSize(v, len);
abc3a514 19#endif
3b96824e 20}
abc3a514
MZ
21%}
22
50280d45
MZ
23%include <typemaps.i>
24%include <cstring.i>
f5b59bd6 25
05c0dae8 26%typemap(in) unsigned char* = char*;
4c5afeb9 27
b060307c
TJ
28%immutable ftdi_version_info::version_str;
29%immutable ftdi_version_info::snapshot_str;
30
4c5afeb9 31%rename("%(strip:[ftdi_])s") "";
b790d38e 32
50280d45
MZ
33%newobject ftdi_new;
34%typemap(newfree) struct ftdi_context *ftdi "ftdi_free($1);";
35%delobject ftdi_free;
36
31fba51d
MZ
37%define ftdi_usb_find_all_docstring
38"usb_find_all(context, vendor, product) -> (return_code, devlist)"
39%enddef
40%feature("autodoc", ftdi_usb_find_all_docstring) ftdi_usb_find_all;
50280d45
MZ
41%typemap(in,numinputs=0) SWIGTYPE** OUTPUT ($*ltype temp) %{ $1 = &temp; %}
42%typemap(argout) SWIGTYPE** OUTPUT %{ $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj((void*)*$1,$*descriptor,0)); %}
43%apply SWIGTYPE** OUTPUT { struct ftdi_device_list **devlist };
44 int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list **devlist,
45 int vendor, int product);
46%clear struct ftdi_device_list **devlist;
47
31fba51d
MZ
48%define ftdi_usb_get_strings_docstring
49"usb_get_strings(context, device) -> (return_code, manufacturer, description, serial)"
50%enddef
51%feature("autodoc", ftdi_usb_get_strings_docstring) ftdi_usb_get_strings;
50280d45 52%apply char *OUTPUT { char * manufacturer, char * description, char * serial };
4c5afeb9
MZ
53%cstring_bounded_output( char * manufacturer, 256 );
54%cstring_bounded_output( char * description, 256 );
55%cstring_bounded_output( char * serial, 256 );
50280d45 56%typemap(default,noblock=1) int mnf_len, int desc_len, int serial_len { $1 = 256; }
4c5afeb9
MZ
57 int ftdi_usb_get_strings(struct ftdi_context *ftdi, struct libusb_device *dev,
58 char * manufacturer, int mnf_len,
59 char * description, int desc_len,
60 char * serial, int serial_len);
50280d45
MZ
61%clear char * manufacturer, char * description, char * serial;
62%clear int mnf_len, int desc_len, int serial_len;
05c0dae8 63
31fba51d
MZ
64%define ftdi_read_data_docstring
65"read_data(context) -> (return_code, buf)"
66%enddef
67%feature("autodoc", ftdi_read_data_docstring) ftdi_read_data;
50d77f8f 68%typemap(in,numinputs=1) (unsigned char *buf, int size) %{ $2 = PyInt_AsLong($input);$1 = (unsigned char*)malloc($2*sizeof(char)); %}
abc3a514 69%typemap(argout) (unsigned char *buf, int size) %{ if(result<0) $2=0; $result = SWIG_Python_AppendOutput($result, convertString((char*)$1, $2)); free($1); %}
05c0dae8 70 int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int size);
50d77f8f 71%clear (unsigned char *buf, int size);
f0005c33 72
05c0dae8
TH
73%apply int *OUTPUT { unsigned int *chunksize };
74 int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
75 int ftdi_write_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
76%clear unsigned int *chunksize;
f0005c33 77
31fba51d
MZ
78%define ftdi_read_pins_docstring
79"read_pins(context) -> (return_code, pins)"
80%enddef
81%feature("autodoc", ftdi_read_pins_docstring) ftdi_read_pins;
05c0dae8
TH
82%apply char *OUTPUT { unsigned char *pins };
83 int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins);
84%clear unsigned char *pins;
f0005c33 85
05c0dae8
TH
86%apply char *OUTPUT { unsigned char *latency };
87 int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency);
f0005c33
TJ
88%clear unsigned char *latency;
89
4c5afeb9 90%apply short *OUTPUT { unsigned short *status };
05c0dae8 91 int ftdi_poll_modem_status(struct ftdi_context *ftdi, unsigned short *status);
f0005c33
TJ
92%clear unsigned short *status;
93
4c5afeb9
MZ
94%apply int *OUTPUT { int* value };
95 int ftdi_get_eeprom_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value value_name, int* value);
96%clear int* value;
f0005c33 97
50d77f8f 98%typemap(in,numinputs=1) (unsigned char *buf, int size) %{ $2 = PyInt_AsLong($input);$1 = (unsigned char*)malloc($2*sizeof(char)); %}
abc3a514 99%typemap(argout) (unsigned char *buf, int size) %{ if(result<0) $2=0; $result = SWIG_Python_AppendOutput($result, convertString((char*)$1, $2)); free($1); %}
50280d45 100 int ftdi_get_eeprom_buf(struct ftdi_context *ftdi, unsigned char * buf, int size);
50d77f8f 101%clear (unsigned char *buf, int size);
50280d45 102
31fba51d
MZ
103%define ftdi_read_eeprom_location_docstring
104"read_eeprom_location(context, eeprom_addr) -> (return_code, eeprom_val)"
105%enddef
106%feature("autodoc", ftdi_read_eeprom_location_docstring) ftdi_read_eeprom_location;
4c5afeb9
MZ
107%apply short *OUTPUT { unsigned short *eeprom_val };
108 int ftdi_read_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr, unsigned short *eeprom_val);
109%clear unsigned short *eeprom_val;
f0005c33 110
31fba51d
MZ
111%define ftdi_read_eeprom_docstring
112"read_eeprom(context) -> (return_code, eeprom)"
113%enddef
114%feature("autodoc", ftdi_read_eeprom_docstring) ftdi_read_eeprom;
115
116%define ftdi_read_chipid_docstring
117"read_pins(context) -> (return_code, chipid)"
118%enddef
119%feature("autodoc", ftdi_read_chipid_docstring) ftdi_read_chipid;
05c0dae8
TH
120%apply int *OUTPUT { unsigned int *chipid };
121 int ftdi_read_chipid(struct ftdi_context *ftdi, unsigned int *chipid);
122%clear unsigned int *chipid;
123
4c5afeb9
MZ
124%include ftdi.h
125%{
126#include <ftdi.h>
127%}
128
129%include ftdi_i.h
130%{
131#include <ftdi_i.h>
132%}
e15345ab
MZ
133
134%pythoncode %{
135__version__ = get_library_version().version_str
136%}