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