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