]> sigrok.org Git - libsigrok.git/blob - src/hardware/testo/protocol.h
Build: Set local include directories in Makefile.am
[libsigrok.git] / src / hardware / testo / protocol.h
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2014 Bert Vermeulen <bert@biot.com>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef LIBSIGROK_HARDWARE_TESTO_PROTOCOL_H
21 #define LIBSIGROK_HARDWARE_TESTO_PROTOCOL_H
22
23 #include <stdint.h>
24 #include <glib.h>
25 #include <libsigrok/libsigrok.h>
26 #include "libsigrok-internal.h"
27
28 #define LOG_PREFIX "testo"
29
30 #define MAX_REPLY_SIZE       128
31 #define MAX_CHANNELS         16
32
33 /* FTDI commands */
34 #define FTDI_SET_MODEMCTRL   0x01
35 #define FTDI_SET_FLOWCTRL    0x02
36 #define FTDI_SET_BAUDRATE    0x03
37 #define FTDI_SET_PARAMS      0x04
38 /* FTDI command values */
39 #define FTDI_BAUDRATE_115200 0x001a
40 #define FTDI_PARAMS_8N1      0x0008
41 #define FTDI_FLOW_NONE       0x0008
42 #define FTDI_MODEM_ALLHIGH   0x0303
43 #define FTDI_INDEX           0x0000
44 /* FTDI USB stuff */
45 #define EP_IN                1 | LIBUSB_ENDPOINT_IN
46 #define EP_OUT               2 | LIBUSB_ENDPOINT_OUT
47
48 struct testo_model {
49         char *name;
50         int request_size;
51         const uint8_t *request;
52 };
53
54 /** Private, per-device-instance driver context. */
55 struct dev_context {
56         /* Model-specific information */
57         const struct testo_model *model;
58
59         /* Acquisition settings */
60         uint64_t limit_msec;
61         uint64_t limit_samples;
62         void *cb_data;
63
64         /* Operational state */
65         gint64 end_time;
66         uint64_t num_samples;
67         uint8_t channel_units[MAX_CHANNELS];
68         int num_channels;
69
70         /* Temporary state across callbacks */
71         struct libusb_transfer *out_transfer;
72         uint8_t reply[MAX_REPLY_SIZE];
73         int reply_size;
74 };
75
76 SR_PRIV int testo_set_serial_params(struct sr_usb_dev_inst *usb);
77 SR_PRIV int testo_probe_channels(struct sr_dev_inst *sdi);
78 SR_PRIV void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer);
79 SR_PRIV int testo_request_packet(const struct sr_dev_inst *sdi);
80 SR_PRIV gboolean testo_check_packet_prefix(uint8_t *buf, int len);
81 SR_PRIV uint16_t crc16_mcrf4xx(uint16_t crc, uint8_t *data, size_t len);
82 SR_PRIV void testo_receive_packet(const struct sr_dev_inst *sdi);
83
84 #endif