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