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 | ||
3b96824e MZ |
13 | PyObject* 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; | |
953a958c MZ |
82 | %typemap(in,numinputs=0) unsigned char *pins ($*ltype temp) %{ $1 = &temp; %} |
83 | %typemap(argout) (unsigned char *pins) %{ $result = SWIG_Python_AppendOutput($result, convertString((char*)$1, 1)); %} | |
05c0dae8 TH |
84 | int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins); |
85 | %clear unsigned char *pins; | |
f0005c33 | 86 | |
953a958c MZ |
87 | %typemap(in,numinputs=0) unsigned char *latency ($*ltype temp) %{ $1 = &temp; %} |
88 | %typemap(argout) (unsigned char *latency) %{ $result = SWIG_Python_AppendOutput($result, convertString((char*)$1, 1)); %} | |
05c0dae8 | 89 | int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency); |
f0005c33 TJ |
90 | %clear unsigned char *latency; |
91 | ||
4c5afeb9 | 92 | %apply short *OUTPUT { unsigned short *status }; |
05c0dae8 | 93 | int ftdi_poll_modem_status(struct ftdi_context *ftdi, unsigned short *status); |
f0005c33 TJ |
94 | %clear unsigned short *status; |
95 | ||
4c5afeb9 MZ |
96 | %apply int *OUTPUT { int* value }; |
97 | int ftdi_get_eeprom_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value value_name, int* value); | |
98 | %clear int* value; | |
f0005c33 | 99 | |
50d77f8f | 100 | %typemap(in,numinputs=1) (unsigned char *buf, int size) %{ $2 = PyInt_AsLong($input);$1 = (unsigned char*)malloc($2*sizeof(char)); %} |
abc3a514 | 101 | %typemap(argout) (unsigned char *buf, int size) %{ if(result<0) $2=0; $result = SWIG_Python_AppendOutput($result, convertString((char*)$1, $2)); free($1); %} |
50280d45 | 102 | int ftdi_get_eeprom_buf(struct ftdi_context *ftdi, unsigned char * buf, int size); |
50d77f8f | 103 | %clear (unsigned char *buf, int size); |
50280d45 | 104 | |
31fba51d MZ |
105 | %define ftdi_read_eeprom_location_docstring |
106 | "read_eeprom_location(context, eeprom_addr) -> (return_code, eeprom_val)" | |
107 | %enddef | |
108 | %feature("autodoc", ftdi_read_eeprom_location_docstring) ftdi_read_eeprom_location; | |
4c5afeb9 MZ |
109 | %apply short *OUTPUT { unsigned short *eeprom_val }; |
110 | int ftdi_read_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr, unsigned short *eeprom_val); | |
111 | %clear unsigned short *eeprom_val; | |
f0005c33 | 112 | |
31fba51d MZ |
113 | %define ftdi_read_eeprom_docstring |
114 | "read_eeprom(context) -> (return_code, eeprom)" | |
115 | %enddef | |
116 | %feature("autodoc", ftdi_read_eeprom_docstring) ftdi_read_eeprom; | |
117 | ||
118 | %define ftdi_read_chipid_docstring | |
953a958c | 119 | "ftdi_read_chipid(context) -> (return_code, chipid)" |
31fba51d MZ |
120 | %enddef |
121 | %feature("autodoc", ftdi_read_chipid_docstring) ftdi_read_chipid; | |
05c0dae8 TH |
122 | %apply int *OUTPUT { unsigned int *chipid }; |
123 | int ftdi_read_chipid(struct ftdi_context *ftdi, unsigned int *chipid); | |
124 | %clear unsigned int *chipid; | |
125 | ||
4c5afeb9 MZ |
126 | %include ftdi.h |
127 | %{ | |
128 | #include <ftdi.h> | |
129 | %} | |
130 | ||
131 | %include ftdi_i.h | |
132 | %{ | |
133 | #include <ftdi_i.h> | |
134 | %} | |
e15345ab MZ |
135 | |
136 | %pythoncode %{ | |
137 | __version__ = get_library_version().version_str | |
138 | %} |