]> sigrok.org Git - libsigrok.git/blob - hardware/tekpower-dmm/protocol.h
Add support for the TekPower TP4000ZC DMM.
[libsigrok.git] / hardware / tekpower-dmm / protocol.h
1 /*
2  * This file is part of the sigrok project.
3  *
4  * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.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_TEKPOWER_DMM_PROTOCOL_H
21 #define LIBSIGROK_HARDWARE_TEKPOWER_DMM_PROTOCOL_H
22
23 /* Message logging helpers with driver-specific prefix string. */
24 #define DRIVER_LOG_DOMAIN "tekpower-dmm: "
25 #define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
26 #define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
27 #define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
28 #define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
29 #define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
30 #define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
31
32 #define DMM_BUFSIZE  256
33
34 /* Flags present in the packet */
35 #define LCD14_AC        (1<<23)
36 #define LCD14_DC        (1<<22)
37 #define LCD14_AUTO      (1<<21)
38 #define LCD14_RS232     (1<<20)
39 #define LCD14_MICRO     (1<<19)
40 #define LCD14_NANO      (1<<18)
41 #define LCD14_KILO      (1<<17)
42 #define LCD14_DIODE     (1<<16)
43 #define LCD14_MILLI     (1<<15)
44 #define LCD14_DUTY      (1<<14)
45 #define LCD14_MEGA      (1<<13)
46 #define LCD14_BEEP      (1<<12)
47 #define LCD14_FARAD     (1<<11)
48 #define LCD14_OHM       (1<<10)
49 #define LCD14_REL       (1<< 9)
50 #define LCD14_HOLD      (1<< 8)
51 #define LCD14_AMP       (1<< 7)
52 #define LCD14_VOLT      (1<< 6)
53 #define LCD14_HZ        (1<< 5)
54 #define LCD14_LOW_BATT  (1<< 4)
55 #define LCD14_HFE       (1<< 3)
56 #define LCD14_CELSIUS   (1<< 2)
57 #define LCD14_RSVD1     (1<< 1)
58 #define LCD14_RSVD0     (0<< 0)
59
60 /* mask to remove the decimal point from a digit */
61 #define LCD14_DP_MASK   (0x80)
62 #define LCD14_D0_NEG    LCD14_DP_MASK
63 /* mask to remove the syncronization nibble */
64 #define LCD14_SYNC_MASK (0xF0)
65
66 /* What the LCD values represent */
67 #define LCD14_LCD_0 0x7d
68 #define LCD14_LCD_1 0x05
69 #define LCD14_LCD_2 0x5b
70 #define LCD14_LCD_3 0x1f
71 #define LCD14_LCD_4 0x27
72 #define LCD14_LCD_5 0x3e
73 #define LCD14_LCD_6 0x7e
74 #define LCD14_LCD_7 0x15
75 #define LCD14_LCD_8 0x7f
76 #define LCD14_LCD_9 0x3f
77
78
79 #define LCD14_LCD_INVALID       0xff
80
81 typedef struct {
82         uint8_t raw[14];
83 } lcd14_packet;
84
85 typedef struct {
86         uint8_t digit[4];
87         uint32_t flags;
88 } lcd14_data;
89
90 #define LCD14_PACKET_SIZE (sizeof(lcd14_packet))
91
92 SR_PRIV gboolean lcd14_is_packet_valid(const lcd14_packet *packet,
93                                        lcd14_data *data);
94
95 /* Private, per-device-instance driver context. */
96 struct dev_context {
97         uint64_t limit_samples;
98         struct sr_serial_dev_inst *serial;
99         char *serialcomm;
100
101         /* Opaque pointer passed in by the frontend. */
102         void *cb_data;
103
104         /* Runtime. */
105         uint64_t num_samples;
106         uint8_t buf[DMM_BUFSIZE];
107         size_t bufoffset;
108         size_t buflen;
109 };
110
111
112 SR_PRIV int lcd14_receive_data(int fd, int revents, void *cb_data);
113
114 #endif /* LIBSIGROK_HARDWARE_TEKPOWER_DMM_PROTOCOL_H */