23 #include "libsigrok-internal.h"
28 #define LOG_PREFIX "serial-ch9325"
31 #ifdef HAVE_SERIAL_COMM
40 #define CH9325_MAX_BYTES_PER_REQUEST 7
42 static const struct vid_pid_item vid_pid_items_ch9325[] = {
53 static int ch9325_set_params(
struct sr_serial_dev_inst *serial,
54 int baudrate,
int bits,
int parity,
int stopbits,
55 int flowcontrol,
int rts,
int dtr)
78 WL16(&report[replen], baudrate);
79 replen +=
sizeof(uint16_t);
80 report[replen++] = 0x00;
81 report[replen++] = 0x00;
82 report[replen++] = bits - 5;
85 sr_dbg(
"DBG: %s() report %s => rc %d", __func__, text->str, rc);
95 static int ch9325_read_bytes(
struct sr_serial_dev_inst *serial,
96 uint8_t *data,
int space,
unsigned int timeout)
98 uint8_t buffer[1 + CH9325_MAX_BYTES_PER_REQUEST];
113 sr_dbg(
"DBG: %s() got report len %d, 0x%02x.", __func__, rc, buffer[0]);
117 if ((count & 0xf0) != 0xf0)
120 sr_dbg(
"DBG: %s(), got %d UART RX bytes.", __func__, count);
125 memcpy(data, &buffer[1], count);
129 static int ch9325_write_bytes(
struct sr_serial_dev_inst *serial,
130 const uint8_t *data,
int size)
132 uint8_t buffer[1 + CH9325_MAX_BYTES_PER_REQUEST];
135 sr_dbg(
"DBG: %s() shall send UART TX data, len %d.", __func__, size);
139 if (size > CH9325_MAX_BYTES_PER_REQUEST) {
140 size = CH9325_MAX_BYTES_PER_REQUEST;
141 sr_dbg(
"DBG: %s() capping size to %d.", __func__, size);
151 memcpy(&buffer[1], data, size);
160 static struct ser_hid_chip_functions chip_ch9325 = {
161 .chipname =
"ch9325",
162 .chipdesc =
"WCH CH9325",
163 .vid_pid_items = vid_pid_items_ch9325,
164 .max_bytes_per_request = CH9325_MAX_BYTES_PER_REQUEST,
165 .set_params = ch9325_set_params,
166 .read_bytes = ch9325_read_bytes,
167 .write_bytes = ch9325_write_bytes,
169 SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_ch9325 = &chip_ch9325;
173 SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_ch9325 = NULL;
Generic/unspecified error.
SR_PRIV int ser_hid_hidapi_set_data(struct sr_serial_dev_inst *serial, uint8_t ep, const uint8_t *data, size_t len, int timeout)
SR_PRIV int ser_hid_hidapi_set_report(struct sr_serial_dev_inst *serial, const uint8_t *data, size_t len)
The public libsigrok header file to be used by frontends.
SR_PRIV GString * sr_hexdump_new(const uint8_t *data, const size_t len)
Convert a sequence of bytes to its textual representation ("hex dump").
SR_PRIV void sr_hexdump_free(GString *s)
Free a hex dump text that was created by sr_hexdump_new().
SR_PRIV int ser_hid_hidapi_get_data(struct sr_serial_dev_inst *serial, uint8_t ep, uint8_t *data, size_t len, int timeout)