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