swig: improve indentation
[libftdi] / python / 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
f64b66d6 13inline PyObject* charp2str(const char *v_, long len)
3b96824e 14{
abc3a514 15#if PY_MAJOR_VERSION >= 3
f64b66d6 16 return PyBytes_FromStringAndSize(v_, len);
abc3a514 17#else
f64b66d6 18 return PyString_FromStringAndSize(v_, len);
abc3a514 19#endif
3b96824e 20}
f64b66d6 21
3eca5150 22char * str2charp_size(PyObject* pyObj, int * size)
f64b66d6
TJ
23{
24 char * v_ = 0;
bfbd47b7 25 Py_ssize_t len = 0;
f64b66d6 26#if PY_MAJOR_VERSION >= 3
bfbd47b7 27 PyBytes_AsStringAndSize(pyObj, &v_, &len);
f64b66d6 28#else
bfbd47b7 29 PyString_AsStringAndSize(pyObj, &v_, &len);
f64b66d6 30#endif
bfbd47b7 31 *size = len;
f64b66d6
TJ
32 return v_;
33}
abc3a514
MZ
34%}
35
50280d45
MZ
36%include <typemaps.i>
37%include <cstring.i>
f5b59bd6 38
05c0dae8 39%typemap(in) unsigned char* = char*;
4c5afeb9 40
b060307c
TJ
41%immutable ftdi_version_info::version_str;
42%immutable ftdi_version_info::snapshot_str;
43
4c5afeb9 44%rename("%(strip:[ftdi_])s") "";
b790d38e 45
50280d45
MZ
46%newobject ftdi_new;
47%typemap(newfree) struct ftdi_context *ftdi "ftdi_free($1);";
48%delobject ftdi_free;
49
31fba51d
MZ
50%define ftdi_usb_find_all_docstring
51"usb_find_all(context, vendor, product) -> (return_code, devlist)"
52%enddef
53%feature("autodoc", ftdi_usb_find_all_docstring) ftdi_usb_find_all;
50280d45
MZ
54%typemap(in,numinputs=0) SWIGTYPE** OUTPUT ($*ltype temp) %{ $1 = &temp; %}
55%typemap(argout) SWIGTYPE** OUTPUT %{ $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj((void*)*$1,$*descriptor,0)); %}
56%apply SWIGTYPE** OUTPUT { struct ftdi_device_list **devlist };
57 int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list **devlist,
58 int vendor, int product);
59%clear struct ftdi_device_list **devlist;
60
31fba51d
MZ
61%define ftdi_usb_get_strings_docstring
62"usb_get_strings(context, device) -> (return_code, manufacturer, description, serial)"
63%enddef
64%feature("autodoc", ftdi_usb_get_strings_docstring) ftdi_usb_get_strings;
a001e73a 65%feature("autodoc", ftdi_usb_get_strings_docstring) ftdi_usb_get_strings2;
b829fe92 66%feature("autodoc", ftdi_usb_get_strings_docstring) ftdi_eeprom_get_strings;
50280d45 67%apply char *OUTPUT { char * manufacturer, char * description, char * serial };
4c5afeb9
MZ
68%cstring_bounded_output( char * manufacturer, 256 );
69%cstring_bounded_output( char * description, 256 );
b829fe92 70%cstring_bounded_output( char * product, 256 );
4c5afeb9 71%cstring_bounded_output( char * serial, 256 );
b829fe92 72%typemap(default,noblock=1) int mnf_len, int desc_len, int product_len, int serial_len { $1 = 256; }
4c5afeb9
MZ
73 int ftdi_usb_get_strings(struct ftdi_context *ftdi, struct libusb_device *dev,
74 char * manufacturer, int mnf_len,
75 char * description, int desc_len,
76 char * serial, int serial_len);
a001e73a
TJ
77 int ftdi_usb_get_strings2(struct ftdi_context *ftdi, struct libusb_device *dev,
78 char * manufacturer, int mnf_len,
79 char * description, int desc_len,
80 char * serial, int serial_len);
b829fe92
TJ
81 int ftdi_eeprom_get_strings(struct ftdi_context *ftdi,
82 char *manufacturer, int mnf_len,
83 char *product, int product_len,
84 char *serial, int serial_len);
85
50280d45 86%clear char * manufacturer, char * description, char * serial;
b829fe92
TJ
87%clear char * product;
88%clear int mnf_len, int desc_len, int product_len, int serial_len;
05c0dae8 89
31fba51d
MZ
90%define ftdi_read_data_docstring
91"read_data(context) -> (return_code, buf)"
92%enddef
93%feature("autodoc", ftdi_read_data_docstring) ftdi_read_data;
50d77f8f 94%typemap(in,numinputs=1) (unsigned char *buf, int size) %{ $2 = PyInt_AsLong($input);$1 = (unsigned char*)malloc($2*sizeof(char)); %}
e6478214
YY
95%typemap(argout) (unsigned char *buf, int size) %{
96 if(result<0)
97 $2=0;
98 $result = SWIG_Python_AppendOutput($result, charp2str((char*)$1, $2));
99 free($1);
100%}
05c0dae8 101 int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int size);
50d77f8f 102%clear (unsigned char *buf, int size);
f0005c33 103
f64b66d6
TJ
104%define ftdi_write_data_docstring
105"write_data(context, data) -> return_code"
106%enddef
107%feature("autodoc", ftdi_write_data_docstring) ftdi_write_data;
108%typemap(in,numinputs=1) (const unsigned char *buf, int size) %{ $1 = (unsigned char*)str2charp_size($input, &$2); %}
109 int ftdi_write_data(struct ftdi_context *ftdi, const unsigned char *buf, int size);
110%clear (const unsigned char *buf, int size);
111
05c0dae8
TH
112%apply int *OUTPUT { unsigned int *chunksize };
113 int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
114 int ftdi_write_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
115%clear unsigned int *chunksize;
f0005c33 116
31fba51d
MZ
117%define ftdi_read_pins_docstring
118"read_pins(context) -> (return_code, pins)"
119%enddef
120%feature("autodoc", ftdi_read_pins_docstring) ftdi_read_pins;
953a958c 121%typemap(in,numinputs=0) unsigned char *pins ($*ltype temp) %{ $1 = &temp; %}
f64b66d6 122%typemap(argout) (unsigned char *pins) %{ $result = SWIG_Python_AppendOutput($result, charp2str((char*)$1, 1)); %}
05c0dae8
TH
123 int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins);
124%clear unsigned char *pins;
f0005c33 125
953a958c 126%typemap(in,numinputs=0) unsigned char *latency ($*ltype temp) %{ $1 = &temp; %}
f64b66d6 127%typemap(argout) (unsigned char *latency) %{ $result = SWIG_Python_AppendOutput($result, charp2str((char*)$1, 1)); %}
05c0dae8 128 int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency);
f0005c33
TJ
129%clear unsigned char *latency;
130
4c5afeb9 131%apply short *OUTPUT { unsigned short *status };
05c0dae8 132 int ftdi_poll_modem_status(struct ftdi_context *ftdi, unsigned short *status);
f0005c33
TJ
133%clear unsigned short *status;
134
4c5afeb9
MZ
135%apply int *OUTPUT { int* value };
136 int ftdi_get_eeprom_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value value_name, int* value);
137%clear int* value;
f0005c33 138
50d77f8f 139%typemap(in,numinputs=1) (unsigned char *buf, int size) %{ $2 = PyInt_AsLong($input);$1 = (unsigned char*)malloc($2*sizeof(char)); %}
e6478214
YY
140%typemap(argout) (unsigned char *buf, int size) %{
141 if(result<0)
142 $2=0;
143 $result = SWIG_Python_AppendOutput($result, charp2str((char*)$1, $2));
144 free($1);
145%}
50280d45 146 int ftdi_get_eeprom_buf(struct ftdi_context *ftdi, unsigned char * buf, int size);
50d77f8f 147%clear (unsigned char *buf, int size);
50280d45 148
31fba51d
MZ
149%define ftdi_read_eeprom_location_docstring
150"read_eeprom_location(context, eeprom_addr) -> (return_code, eeprom_val)"
151%enddef
152%feature("autodoc", ftdi_read_eeprom_location_docstring) ftdi_read_eeprom_location;
4c5afeb9
MZ
153%apply short *OUTPUT { unsigned short *eeprom_val };
154 int ftdi_read_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr, unsigned short *eeprom_val);
155%clear unsigned short *eeprom_val;
f0005c33 156
31fba51d
MZ
157%define ftdi_read_eeprom_docstring
158"read_eeprom(context) -> (return_code, eeprom)"
159%enddef
160%feature("autodoc", ftdi_read_eeprom_docstring) ftdi_read_eeprom;
161
162%define ftdi_read_chipid_docstring
953a958c 163"ftdi_read_chipid(context) -> (return_code, chipid)"
31fba51d
MZ
164%enddef
165%feature("autodoc", ftdi_read_chipid_docstring) ftdi_read_chipid;
05c0dae8
TH
166%apply int *OUTPUT { unsigned int *chipid };
167 int ftdi_read_chipid(struct ftdi_context *ftdi, unsigned int *chipid);
168%clear unsigned int *chipid;
169
4c5afeb9
MZ
170%include ftdi.h
171%{
172#include <ftdi.h>
173%}
174
175%include ftdi_i.h
176%{
177#include <ftdi_i.h>
178%}
e15345ab
MZ
179
180%pythoncode %{
181__version__ = get_library_version().version_str
182%}