diff options
Diffstat (limited to 'userland/cp210x.h')
-rw-r--r-- | userland/cp210x.h | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/userland/cp210x.h b/userland/cp210x.h new file mode 100644 index 0000000..4b9beff --- /dev/null +++ b/userland/cp210x.h @@ -0,0 +1,97 @@ +#ifndef _CP210X_H_ +#define _CP210X_H_ + +#include <libusb.h> +typedef struct { + libusb_device *device; + libusb_device_handle *handle; + int interface; +} CP210X; + +struct cp210x_port_state { + uint16_t mode; /* push-pull = 1, open-drain = 0 */ + uint16_t low_power; /* 1 = ground the pin, and disable */ + uint16_t latch; +} __attribute__((packed)); + +/* LOPWR MODE LATCH */ +/* 0 0 0 Pin drivers are totem pole, and inital config sinks current to GND */ +/* 0 0 1 Pin drivers are totem pole, and inital config sources current from VIO */ +/* 0 1 0 Pin drivers are open drain, and inital config sinks current to GND */ +/* 0 1 1 Pin drivers are open drain, and inital config leaves pin HI-Z (you want this for inputs) */ +/* 1 X X Pin drivers are disabled, and pin sinks current to GND */ + +struct cp210x_port_config { + struct cp210x_port_state reset; + struct cp210x_port_state suspend; + uint8_t enhanced_fxn; +} __attribute__((packed)); + + +#define CP_EFXN_GPIO_0_IS_TXLED (1 << 0) +#define CP_EFXN_GPIO_1_IS_RXLED (1 << 1) +#define CP_EFXN_GPIO_2_IS_RS485_TX (1 << 2) +#define CP_EFXN_UNUSED_1 (1 << 3) /* Set to zero */ +#define CP_EFXN_ENABLE_WPU (1 << 4) +#define CP_EFXN_UNUSED_2 (1 << 5) /* Set to zero */ +#define CP_EFXN_SERIAL_AUTOOFF (1 << 6) +#define CP_EFXN_GPIOL_AUTOOFF (1 << 7) + + +#define CP_PIN_RI (1 << 0) +#define CP_PIN_DCD (1 << 1) +#define CP_PIN_DTR (1 << 2) +#define CP_PIN_DSR (1 << 3) +#define CP_PIN_TXD (1 << 4) +#define CP_PIN_RXD (1 << 5) +#define CP_PIN_RTS (1 << 6) +#define CP_PIN_CTS (1 << 7) +#define CP_PIN_GPIO_0 (1 << 8) +#define CP_PIN_GPIO_1 (1 << 9) +#define CP_PIN_GPIO_2 (1 << 10) +#define CP_PIN_GPIO_3 (1 << 11) +#define CP_PIN_UNUSED_1 (1 << 12) +#define CP_PIN_UNUSED_2 (1 << 13) +#define CP_PIN_GPIO_SUSPEND (1 << 14) +#define CP_PIN_GPIO_NSUSPEND (1 << 15) + +#define CP_INPUT_PINS (CP_PIN_RXD|CP_PIN_CTS|CP_PIN_DSR|CP_PIN_RI|CP_PIN_DCD) + + + + + + +/* CP2103 GPIO */ +#define CP_GPIO_0 0x01 +#define CP_GPIO_1 0x02 +#define CP_GPIO_2 0x04 +#define CP_GPIO_3 0x08 +#define CP_GPIO_MASK (CP_GPIO_0|CP_GPIO_1|CP_GPIO_2|CP_GPIO_3) + + +#define CP210X_MAX_PRODUCT_STRLEN 0x7d +#define CP210X_MAX_SERIAL_STRLEN 0x3f +#define CP210X_MAX_MFG_STRLEN 0x18 +#define CP210X_MAX_MAXPOWER 250 + + + + +extern int cp210x_set_config(CP210X *c, uint8_t request, unsigned int *data, int size); +extern int cp210x_set_gpio(CP210X *c, uint8_t gpio); +extern int cp210x_set_portconf(CP210X *c, struct cp210x_port_config *config); +extern int cp210x_get_portconf(CP210X *c, struct cp210x_port_config *config); +extern int cp210x_set_dtr(CP210X *c, int on); +extern int cp210x_set_vid(CP210X *c, uint16_t vid); +extern int cp210x_set_pid(CP210X *c, uint16_t pid); +extern int cp210x_set_dev_ver(CP210X *c, uint16_t ver); +extern ssize_t cp210x_read(CP210X *c, void *buf, size_t len, unsigned int timeout); +extern int cp210x_set_mfg(CP210X *c, uint8_t *s, int len); +extern int cp210x_set_product(CP210X *c, uint8_t *s, int len); +extern int cp210x_set_serial(CP210X *c, uint8_t *s, int len); +extern int cp210x_setup(CP210X *c); +extern int cp210x_reset(CP210X *c); +extern CP210X *cp210x_open(void); +extern void cp210x_close(CP210X *c); +#endif |