54a45e6aeede3f08e3b8a85dd621b9425000f9af
[libftdi] / bindings / ftdi.i
1 /* File: ftdi.i */
2
3 %module(docstring="Python interface to libftdi") ftdi
4
5 %include <typemaps.i>
6 %include <cstring.i>
7
8 %typemap(in) unsigned char* = char*;
9
10 %ignore ftdi_write_data_async;
11 %ignore ftdi_async_complete;
12
13 %immutable ftdi_version_info::version_str;
14 %immutable ftdi_version_info::snapshot_str;
15
16 %rename("%(strip:[ftdi_])s") "";
17
18 %newobject ftdi_new;
19 %typemap(newfree) struct ftdi_context *ftdi "ftdi_free($1);";
20 %delobject ftdi_free;
21
22 %typemap(in,numinputs=0) SWIGTYPE** OUTPUT ($*ltype temp) %{ $1 = &temp; %}
23 %typemap(argout) SWIGTYPE** OUTPUT %{ $result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj((void*)*$1,$*descriptor,0)); %}
24 %apply SWIGTYPE** OUTPUT { struct ftdi_device_list **devlist };
25     int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list **devlist,
26                           int vendor, int product);
27 %clear struct ftdi_device_list **devlist;
28
29 %apply char *OUTPUT { char * manufacturer, char * description, char * serial };
30 %cstring_bounded_output( char * manufacturer, 256 );
31 %cstring_bounded_output( char * description, 256 );
32 %cstring_bounded_output( char * serial, 256 );
33 %typemap(default,noblock=1) int mnf_len, int desc_len, int serial_len { $1 = 256; }
34     int ftdi_usb_get_strings(struct ftdi_context *ftdi, struct libusb_device *dev,
35                              char * manufacturer, int mnf_len,
36                              char * description, int desc_len,
37                              char * serial, int serial_len);
38 %clear char * manufacturer, char * description, char * serial;
39 %clear int mnf_len, int desc_len, int serial_len;
40
41 %apply char *OUTPUT { unsigned char *buf };
42     int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int size);
43 %clear unsigned char *buf;
44
45 %apply int *OUTPUT { unsigned int *chunksize };
46     int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
47     int ftdi_write_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
48 %clear unsigned int *chunksize;
49
50 %apply char *OUTPUT { unsigned char *pins };
51     int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins);
52 %clear unsigned char *pins;
53
54 %apply char *OUTPUT { unsigned char *latency };
55     int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency);
56 %clear unsigned char *latency;
57
58 %apply short *OUTPUT { unsigned short *status };
59     int ftdi_poll_modem_status(struct ftdi_context *ftdi, unsigned short *status);
60 %clear unsigned short *status;
61
62 %apply int *OUTPUT { int* value };
63     int ftdi_get_eeprom_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value value_name, int* value);
64 %clear int* value;
65
66 %apply char *OUTPUT { unsigned char *buf };
67 %typemap(in,numinputs=0) unsigned char *buf(char temp[FTDI_MAX_EEPROM_SIZE]) %{ $1 = ($1_ltype) temp; %}
68 %typemap(freearg,match="in") unsigned char *buf "";
69 %typemap(argout,fragment="SWIG_FromCharPtrAndSize") unsigned char *buf %{ $result = SWIG_Python_AppendOutput($result, SWIG_FromCharPtrAndSize((char*)$1,FTDI_MAX_EEPROM_SIZE)); %}
70 %typemap(default,noblock=1) int size { $1 = 128; }
71     int ftdi_get_eeprom_buf(struct ftdi_context *ftdi, unsigned char * buf, int size);
72 %clear unsigned char *buf;
73 %clear int size;
74
75 %apply short *OUTPUT { unsigned short *eeprom_val };
76     int ftdi_read_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr, unsigned short *eeprom_val);
77 %clear unsigned short *eeprom_val;
78
79 %apply int *OUTPUT { unsigned int *chipid };
80     int ftdi_read_chipid(struct ftdi_context *ftdi, unsigned int *chipid);
81 %clear unsigned int *chipid;
82
83 %include ftdi.h
84 %{
85 #include <ftdi.h>
86 %}
87
88 %include ftdi_i.h
89 %{
90 #include <ftdi_i.h>
91 %}