+++ /dev/null
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3.29
- *
- * Do not make changes to this file unless you know what you are doing--modify
- * the SWIG interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package com.ftdi.usb;
-
-public class SWIGTYPE_p_ftdi_context {
- private long swigCPtr;
-
- protected SWIGTYPE_p_ftdi_context(long cPtr, boolean futureUse) {
- swigCPtr = cPtr;
- }
-
- protected SWIGTYPE_p_ftdi_context() {
- swigCPtr = 0;
- }
-
- protected static long getCPtr(SWIGTYPE_p_ftdi_context obj) {
- return (obj == null) ? 0 : obj.swigCPtr;
- }
-}
-
+++ /dev/null
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3.29
- *
- * Do not make changes to this file unless you know what you are doing--modify
- * the SWIG interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package com.ftdi.usb;
-
-public class SWIGTYPE_p_ftdi_eeprom {
- private long swigCPtr;
-
- protected SWIGTYPE_p_ftdi_eeprom(long cPtr, boolean futureUse) {
- swigCPtr = cPtr;
- }
-
- protected SWIGTYPE_p_ftdi_eeprom() {
- swigCPtr = 0;
- }
-
- protected static long getCPtr(SWIGTYPE_p_ftdi_eeprom obj) {
- return (obj == null) ? 0 : obj.swigCPtr;
- }
-}
-
+++ /dev/null
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3.29
- *
- * Do not make changes to this file unless you know what you are doing--modify
- * the SWIG interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package com.ftdi.usb;
-
-public class SWIGTYPE_p_p_ftdi_device_list {
- private long swigCPtr;
-
- protected SWIGTYPE_p_p_ftdi_device_list(long cPtr, boolean futureUse) {
- swigCPtr = cPtr;
- }
-
- protected SWIGTYPE_p_p_ftdi_device_list() {
- swigCPtr = 0;
- }
-
- protected static long getCPtr(SWIGTYPE_p_p_ftdi_device_list obj) {
- return (obj == null) ? 0 : obj.swigCPtr;
- }
-}
-
+++ /dev/null
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3.29
- *
- * Do not make changes to this file unless you know what you are doing--modify
- * the SWIG interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package com.ftdi.usb;
-
-public class SWIGTYPE_p_unsigned_char {
- private long swigCPtr;
-
- protected SWIGTYPE_p_unsigned_char(long cPtr, boolean futureUse) {
- swigCPtr = cPtr;
- }
-
- protected SWIGTYPE_p_unsigned_char() {
- swigCPtr = 0;
- }
-
- protected static long getCPtr(SWIGTYPE_p_unsigned_char obj) {
- return (obj == null) ? 0 : obj.swigCPtr;
- }
-}
-
+++ /dev/null
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3.29
- *
- * Do not make changes to this file unless you know what you are doing--modify
- * the SWIG interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package com.ftdi.usb;
-
-public class SWIGTYPE_p_unsigned_int {
- private long swigCPtr;
-
- protected SWIGTYPE_p_unsigned_int(long cPtr, boolean futureUse) {
- swigCPtr = cPtr;
- }
-
- protected SWIGTYPE_p_unsigned_int() {
- swigCPtr = 0;
- }
-
- protected static long getCPtr(SWIGTYPE_p_unsigned_int obj) {
- return (obj == null) ? 0 : obj.swigCPtr;
- }
-}
-
+++ /dev/null
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3.29
- *
- * Do not make changes to this file unless you know what you are doing--modify
- * the SWIG interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package com.ftdi.usb;
-
-public class SWIGTYPE_p_usb_dev_handle {
- private long swigCPtr;
-
- protected SWIGTYPE_p_usb_dev_handle(long cPtr, boolean futureUse) {
- swigCPtr = cPtr;
- }
-
- protected SWIGTYPE_p_usb_dev_handle() {
- swigCPtr = 0;
- }
-
- protected static long getCPtr(SWIGTYPE_p_usb_dev_handle obj) {
- return (obj == null) ? 0 : obj.swigCPtr;
- }
-}
-
+++ /dev/null
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3.29
- *
- * Do not make changes to this file unless you know what you are doing--modify
- * the SWIG interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package com.ftdi.usb;
-
-public class SWIGTYPE_p_usb_device {
- private long swigCPtr;
-
- protected SWIGTYPE_p_usb_device(long cPtr, boolean futureUse) {
- swigCPtr = cPtr;
- }
-
- protected SWIGTYPE_p_usb_device() {
- swigCPtr = 0;
- }
-
- protected static long getCPtr(SWIGTYPE_p_usb_device obj) {
- return (obj == null) ? 0 : obj.swigCPtr;
- }
-}
-
return exampleJNI.ftdi_init(SWIGTYPE_p_ftdi_context.getCPtr(ftdi));
}
+ public static int ftdi_read_data(SWIGTYPE_p_ftdi_context ftdi, byte[] buf, int size) {
+ return exampleJNI.ftdi_read_data(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), buf, size);
+ }
+
+ public static int ftdi_write_data(SWIGTYPE_p_ftdi_context ftdi, byte[] buf, int size) {
+ return exampleJNI.ftdi_write_data(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), buf, size);
+ }
+
+ public static int ftdi_usb_open(SWIGTYPE_p_ftdi_context ftdi, int vendor, int product) {
+ return exampleJNI.ftdi_usb_open(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), vendor, product);
+ }
+
+ public static int ftdi_set_baudrate(SWIGTYPE_p_ftdi_context ftdi, int baudrate) {
+ return exampleJNI.ftdi_set_baudrate(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), baudrate);
+ }
+
+ public static int ftdi_set_line_property(SWIGTYPE_p_ftdi_context ftdi, int bits, int sbit, int parity) {
+ return exampleJNI.ftdi_set_line_property(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), bits, sbit, parity);
+ }
+
+ public static int ftdi_set_bitmode(SWIGTYPE_p_ftdi_context ftdi, short bitmask, short mode) {
+ return exampleJNI.ftdi_set_bitmode(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), bitmask, mode);
+ }
+
+ public static int ftdi_read_pins(SWIGTYPE_p_ftdi_context ftdi, byte[] pins) {
+ return exampleJNI.ftdi_read_pins(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), pins);
+ }
+
+ public static int ftdi_setflowctrl(SWIGTYPE_p_ftdi_context ftdi, int flowctrl) {
+ return exampleJNI.ftdi_setflowctrl(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), flowctrl);
+ }
+
public static void ftdi_deinit(SWIGTYPE_p_ftdi_context ftdi) {
exampleJNI.ftdi_deinit(SWIGTYPE_p_ftdi_context.getCPtr(ftdi));
}
exampleJNI.ftdi_list_free(SWIGTYPE_p_p_ftdi_device_list.getCPtr(devlist));
}
- public static int ftdi_usb_open(SWIGTYPE_p_ftdi_context ftdi, int vendor, int product) {
- return exampleJNI.ftdi_usb_open(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), vendor, product);
- }
-
public static int ftdi_usb_open_desc(SWIGTYPE_p_ftdi_context ftdi, int vendor, int product, String description, String serial) {
return exampleJNI.ftdi_usb_open_desc(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), vendor, product, description, serial);
}
return exampleJNI.ftdi_usb_purge_buffers(SWIGTYPE_p_ftdi_context.getCPtr(ftdi));
}
- public static int ftdi_set_baudrate(SWIGTYPE_p_ftdi_context ftdi, int baudrate) {
- return exampleJNI.ftdi_set_baudrate(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), baudrate);
- }
-
- public static int ftdi_set_line_property(SWIGTYPE_p_ftdi_context ftdi, int bits, int sbit, int parity) {
- return exampleJNI.ftdi_set_line_property(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), bits, sbit, parity);
- }
-
- public static int ftdi_read_data(SWIGTYPE_p_ftdi_context ftdi, byte[] buf, int size) {
- return exampleJNI.ftdi_read_data(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), buf, size);
- }
-
public static int ftdi_read_data_set_chunksize(SWIGTYPE_p_ftdi_context ftdi, long chunksize) {
return exampleJNI.ftdi_read_data_set_chunksize(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), chunksize);
}
return exampleJNI.ftdi_read_data_get_chunksize(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), SWIGTYPE_p_unsigned_int.getCPtr(chunksize));
}
- public static int ftdi_write_data(SWIGTYPE_p_ftdi_context ftdi, byte[] buf, int size) {
- return exampleJNI.ftdi_write_data(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), buf, size);
- }
-
public static int ftdi_write_data_set_chunksize(SWIGTYPE_p_ftdi_context ftdi, long chunksize) {
return exampleJNI.ftdi_write_data_set_chunksize(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), chunksize);
}
return exampleJNI.ftdi_disable_bitbang(SWIGTYPE_p_ftdi_context.getCPtr(ftdi));
}
- public static int ftdi_set_bitmode(SWIGTYPE_p_ftdi_context ftdi, short bitmask, short mode) {
- return exampleJNI.ftdi_set_bitmode(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), bitmask, mode);
- }
-
- public static int ftdi_read_pins(SWIGTYPE_p_ftdi_context ftdi, byte[] pins) {
- return exampleJNI.ftdi_read_pins(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), pins);
- }
-
- public static int ftdi_setflowctrl(SWIGTYPE_p_ftdi_context ftdi, int flowctrl) {
- return exampleJNI.ftdi_setflowctrl(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), flowctrl);
- }
-
public static int ftdi_set_latency_timer(SWIGTYPE_p_ftdi_context ftdi, short latency) {
return exampleJNI.ftdi_set_latency_timer(SWIGTYPE_p_ftdi_context.getCPtr(ftdi), latency);
}
public final static native long new_ftdi_context();
public final static native long new_ftdi_eeprom();
public final static native int ftdi_init(long jarg1);
+ public final static native int ftdi_read_data(long jarg1, byte[] jarg2, int jarg3);
+ public final static native int ftdi_write_data(long jarg1, byte[] jarg2, int jarg3);
+ public final static native int ftdi_usb_open(long jarg1, int jarg2, int jarg3);
+ public final static native int ftdi_set_baudrate(long jarg1, int jarg2);
+ public final static native int ftdi_set_line_property(long jarg1, int jarg2, int jarg3, int jarg4);
+ public final static native int ftdi_set_bitmode(long jarg1, short jarg2, short jarg3);
+ public final static native int ftdi_read_pins(long jarg1, byte[] jarg2);
+ public final static native int ftdi_setflowctrl(long jarg1, int jarg2);
public final static native void ftdi_deinit(long jarg1);
public final static native void ftdi_set_usbdev(long jarg1, long jarg2);
public final static native int ftdi_usb_find_all(long jarg1, long jarg2, int jarg3, int jarg4);
public final static native void ftdi_list_free(long jarg1);
- public final static native int ftdi_usb_open(long jarg1, int jarg2, int jarg3);
public final static native int ftdi_usb_open_desc(long jarg1, int jarg2, int jarg3, String jarg4, String jarg5);
public final static native int ftdi_usb_open_dev(long jarg1, long jarg2);
public final static native int ftdi_usb_close(long jarg1);
public final static native int ftdi_usb_reset(long jarg1);
public final static native int ftdi_usb_purge_buffers(long jarg1);
- public final static native int ftdi_set_baudrate(long jarg1, int jarg2);
- public final static native int ftdi_set_line_property(long jarg1, int jarg2, int jarg3, int jarg4);
- public final static native int ftdi_read_data(long jarg1, byte[] jarg2, int jarg3);
public final static native int ftdi_read_data_set_chunksize(long jarg1, long jarg2);
public final static native int ftdi_read_data_get_chunksize(long jarg1, long jarg2);
- public final static native int ftdi_write_data(long jarg1, byte[] jarg2, int jarg3);
public final static native int ftdi_write_data_set_chunksize(long jarg1, long jarg2);
public final static native int ftdi_write_data_get_chunksize(long jarg1, long jarg2);
public final static native int ftdi_enable_bitbang(long jarg1, short jarg2);
public final static native int ftdi_disable_bitbang(long jarg1);
- public final static native int ftdi_set_bitmode(long jarg1, short jarg2, short jarg3);
- public final static native int ftdi_read_pins(long jarg1, byte[] jarg2);
- public final static native int ftdi_setflowctrl(long jarg1, int jarg2);
public final static native int ftdi_set_latency_timer(long jarg1, short jarg2);
public final static native int ftdi_get_latency_timer(long jarg1, long jarg2);
public final static native void ftdi_eeprom_initdefaults(long jarg1);
%}
+%exception ftdi_init {
+ $action
+ if (result) {
+ jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+ (*jenv)->ThrowNew(jenv, clazz, "ftdi_init() returned nonzero result");
+ return $null;
+ }
+}
int ftdi_init(struct ftdi_context *ftdi);
+
+%exception ftdi_read_data {
+ $action
+ if (result<0) {
+ jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+ (*jenv)->ThrowNew(jenv, clazz, "ftdi_read_data() returned negative result");
+ return $null;
+ }
+}
+int ftdi_read_data(struct ftdi_context *ftdi, signed char buf[], int size);
+
+%exception ftdi_write_data {
+ $action
+ if (result<0) {
+ jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+ (*jenv)->ThrowNew(jenv, clazz, "ftdi_write_data() returned negative result");
+ return $null;
+ }
+}
+int ftdi_write_data(struct ftdi_context *ftdi, signed char buf[], int size);
+
+%exception ftdi_usb_open {
+ $action
+ if (result) {
+ jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+ (*jenv)->ThrowNew(jenv, clazz, "ftdi_usb_open() returned nonzero result");
+ return $null;
+ }
+}
+int ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int product);
+
+%exception ftdi_set_baudrate {
+ $action
+ if (result) {
+ jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+ (*jenv)->ThrowNew(jenv, clazz, "ftdftdi_set_baudrate() returned nonzero result");
+ return $null;
+ }
+}
+int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate);
+
+%exception ftdi_set_line_property {
+ $action
+ if (result) {
+ jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+ (*jenv)->ThrowNew(jenv, clazz, "ftdi_set_line_property() returned nonzero result");
+ return $null;
+ }
+}
+int ftdi_set_line_property(struct ftdi_context *ftdi, int bits, int sbit, int parity);
+
+%exception ftdi_set_bitmode {
+ $action
+ if (result) {
+ jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+ (*jenv)->ThrowNew(jenv, clazz, "ftftdi_set_bitmodeeturned nonzero result");
+ return $null;
+ }
+}
+int ftdi_set_bitmode(struct ftdi_context *ftdi, unsigned char bitmask, unsigned char mode);
+
+%exception ftdi_read_pins {
+ $action
+ if (result<0) {
+ jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+ (*jenv)->ThrowNew(jenv, clazz, "ftdi_read_pins() returned negative result");
+ return $null;
+ }
+}
+int ftdi_read_pins(struct ftdi_context *ftdi, signed char pins[]);
+
+%exception ftdi_setflowctrl {
+ $action
+ if (result) {
+ jclass clazz = (*jenv)->FindClass(jenv, "java/lang/RuntimeException");
+ (*jenv)->ThrowNew(jenv, clazz, "ftdi_setflowctrleturned nonzero result");
+ return $null;
+ }
+}
+int ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl);
+
+
/*
int ftdi_set_interface(struct ftdi_context *ftdi, enum ftdi_interface interface);
*/
int vendor, int product);
void ftdi_list_free(struct ftdi_device_list **devlist);
-int ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int product);
int ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int product,
const char* description, const char* serial);
int ftdi_usb_open_dev(struct ftdi_context *ftdi, struct usb_device *dev);
int ftdi_usb_reset(struct ftdi_context *ftdi);
int ftdi_usb_purge_buffers(struct ftdi_context *ftdi);
-int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate);
-
-int ftdi_set_line_property(struct ftdi_context *ftdi, int bits,
- int sbit, int parity);
-
-int ftdi_read_data(struct ftdi_context *ftdi, signed char buf[], int size);
int ftdi_read_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize);
int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
-int ftdi_write_data(struct ftdi_context *ftdi, signed char buf[], int size);
int ftdi_write_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize);
int ftdi_write_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
int ftdi_enable_bitbang(struct ftdi_context *ftdi, unsigned char bitmask);
int ftdi_disable_bitbang(struct ftdi_context *ftdi);
-int ftdi_set_bitmode(struct ftdi_context *ftdi, unsigned char bitmask, unsigned char mode);
-int ftdi_read_pins(struct ftdi_context *ftdi, signed char pins[]);
-
-int ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl);
int ftdi_set_latency_timer(struct ftdi_context *ftdi, unsigned char latency);
int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency);
void ftdi_eeprom_initdefaults(struct ftdi_eeprom *eeprom);
int ftdi_eeprom_build(struct ftdi_eeprom *eeprom, signed char output[]);
-// "eeprom" needs to be valid 128 byte eeprom (generated by the eeprom generator)
-// the checksum of the eeprom is valided
-
int ftdi_read_eeprom(struct ftdi_context *ftdi, signed char eeprom[]);
int ftdi_write_eeprom(struct ftdi_context *ftdi, signed char eeprom[]);
int ftdi_erase_eeprom(struct ftdi_context *ftdi);
import java.io.*;
public class FtdiChip {
- protected SWIGTYPE_p_ftdi_context context;
- protected int bits = 0;
- public FtdiChip() {
- context = example.new_ftdi_context();
-
- int result = example.ftdi_init(context);
- if (result != 0)
- throw new RuntimeException("ftdi_initErr() returned " + result);
-
- result = example.ftdi_usb_open(context, 0x6666, 0x3133);
- if (result != 0)
- throw new RuntimeException("ftdi_usb_open() returned " + result);
- int result = example.ftdi_set_baudrate(context, 750 * 1000);
- if (result != 0)
- throw new RuntimeException("ftdi_set_baudrate() returned " + result);
+ protected int bits = 0;
+ protected SWIGTYPE_p_ftdi_context context = example.new_ftdi_context();
- result = example.ftdi_set_line_property(context, 8, 0, 0);
- if (result != 0)
- throw new RuntimeException("ftdi_set_baudrate() returned " + result);
+ public FtdiChip() {
+ example.ftdi_init(context);
+ example.ftdi_usb_open(context, 0x6666, 0x3133);
+ example.ftdi_set_baudrate(context, 750 * 1000);
+ example.ftdi_set_line_property(context, 8, 0, 0);
}
public synchronized int readPins() {
byte[] b = new byte[1];
- int result = example.ftdi_read_pins(context, b);
- if (result != 0)
- throw new RuntimeException("ftdi_read_pins() returned " + result);
+ example.ftdi_read_pins(context, b);
return b[0];
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos = new ByteArrayOutputStream();
dbang(bytes, bytes.length);
}
- public boolean buffered = false;
+ public boolean buffered = false;
protected static int mask =
(1<<0) |
(1<<1)// |
protected static int dmask =
//(1<<0) |
-
(1<<1) |
(1<<2) |
-
//(1<<3) |
//(1<<4) |
(1<<5) |
int result = example.ftdi_setflowctrl(context, (1 << 8));
if (result != 0)
- throw new RuntimeException("ftdi_setflowcontrol() returned " +
- result);
+ throw new RuntimeException("ftdi_setflowcontrol() returned " + result);
}
public synchronized void uart() {
-
- result = example.ftdi_set_bitmode(context, (short)0, (short)0x00);
+ int result = example.ftdi_set_bitmode(context, (short)0, (short)0x00);
if (result != 0)
throw new RuntimeException("ftdi_set_bitmode() returned " + result);
-
result = example.ftdi_setflowctrl(context, (1 << 8));
if (result != 0)
- throw new RuntimeException("ftdi_setflowcontrol() returned " +
- result);
-
+ throw new RuntimeException("ftdi_setflowcontrol() returned " + result);
}
public synchronized void dbangmode() {
int result = example.ftdi_set_bitmode(context, (short)dmask, (short)0x01);
dbang((byte)dbits);
}
}
- int write = 0;
+
protected synchronized void dbang(byte by) {
byte[] b = new byte[1];
b[0] = by;
if (result != 1)
throw new RuntimeException("ftdi_write_data() returned " + result);
}
- int queued = 0;
protected synchronized void dbang(byte[] b, int len) {
example.ftdi_write_data(context, b, len);
}