]> sigrok.org Git - libsigrok.git/blob - hardware/radioshack-dmm/radioshack-dmm.h
b63ea7d83236582214901eb13e96e355eca4273e
[libsigrok.git] / hardware / radioshack-dmm / radioshack-dmm.h
1 /*
2  * This file is part of the sigrok project.
3  *
4  * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
5  * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #ifndef LIBSIGROK_HARDWARE_RADIOSHACK_DMM_RADIOSHACK_DMM_H
22 #define LIBSIGROK_HARDWARE_RADIOSHACK_DMM_RADIOSHACK_DMM_H
23
24 /* Message logging helpers with driver-specific prefix string. */
25 #define DRIVER_LOG_DOMAIN "radioshack-dmm: "
26 #define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
27 #define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
28 #define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
29 #define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
30 #define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
31 #define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
32
33 #define RS_DMM_BUFSIZE          256
34
35 /* Byte 1 of the packet, and the modes it represents */
36 #define RS_22_812_IND1_HZ       0x80
37 #define RS_22_812_IND1_OHM      0x40
38 #define RS_22_812_IND1_KILO     0x20
39 #define RS_22_812_IND1_MEGA     0x10
40 #define RS_22_812_IND1_FARAD    0x08
41 #define RS_22_812_IND1_AMP      0x04
42 #define RS_22_812_IND1_VOLT     0x02
43 #define RS_22_812_IND1_MILI     0x01
44 /* Byte 2 of the packet, and the modes it represents */
45 #define RS_22_812_IND2_MICRO    0x80
46 #define RS_22_812_IND2_NANO     0x40
47 #define RS_22_812_IND2_DBM      0x20
48 #define RS_22_812_IND2_SEC      0x10
49 #define RS_22_812_IND2_DUTY     0x08
50 #define RS_22_812_IND2_HFE      0x04
51 #define RS_22_812_IND2_REL      0x02
52 #define RS_22_812_IND2_MIN      0x01
53 /* Byte 7 of the packet, and the modes it represents */
54 #define RS_22_812_INFO_BEEP     0x80
55 #define RS_22_812_INFO_DIODE    0x30
56 #define RS_22_812_INFO_BAT      0x20
57 #define RS_22_812_INFO_HOLD     0x10
58 #define RS_22_812_INFO_NEG      0x08
59 #define RS_22_812_INFO_AC       0x04
60 #define RS_22_812_INFO_RS232    0x02
61 #define RS_22_812_INFO_AUTO     0x01
62 /* Instead of a decimal point, digit 4 carries the MAX flag */
63 #define RS_22_812_DIG4_MAX      0x08
64 /* Mask to remove the decimal point from a digit */
65 #define RS_22_812_DP_MASK       0x08
66
67 /* What the LCD values represent */
68 #define RS_22_812_LCD_0         0xd7
69 #define RS_22_812_LCD_1         0x50
70 #define RS_22_812_LCD_2         0xb5
71 #define RS_22_812_LCD_3         0xf1
72 #define RS_22_812_LCD_4         0x72
73 #define RS_22_812_LCD_5         0xe3
74 #define RS_22_812_LCD_6         0xe7
75 #define RS_22_812_LCD_7         0x51
76 #define RS_22_812_LCD_8         0xf7
77 #define RS_22_812_LCD_9         0xf3
78
79 #define RS_22_812_LCD_C         0x87
80 #define RS_22_812_LCD_E
81 #define RS_22_812_LCD_F
82 #define RS_22_812_LCD_h         0x66
83 #define RS_22_812_LCD_H         0x76
84 #define RS_22_812_LCD_I
85 #define RS_22_812_LCD_n
86 #define RS_22_812_LCD_P         0x37
87 #define RS_22_812_LCD_r
88
89 #define RS_22_812_PACKET_SIZE   9
90
91 struct rs_22_812_packet {
92         uint8_t mode;
93         uint8_t indicatrix1;
94         uint8_t indicatrix2;
95         uint8_t digit4;
96         uint8_t digit3;
97         uint8_t digit2;
98         uint8_t digit1;
99         uint8_t info;
100         uint8_t checksum;
101 };
102
103 enum {
104         RS_22_812_MODE_DC_V             = 0,
105         RS_22_812_MODE_AC_V             = 1,
106         RS_22_812_MODE_DC_UA            = 2,
107         RS_22_812_MODE_DC_MA            = 3,
108         RS_22_812_MODE_DC_A             = 4,
109         RS_22_812_MODE_AC_UA            = 5,
110         RS_22_812_MODE_AC_MA            = 6,
111         RS_22_812_MODE_AC_A             = 7,
112         RS_22_812_MODE_OHM              = 8,
113         RS_22_812_MODE_FARAD            = 9,
114         RS_22_812_MODE_HZ               = 10,
115         RS_22_812_MODE_VOLT_HZ          = 11,
116         RS_22_812_MODE_AMP_HZ           = 12,
117         RS_22_812_MODE_DUTY             = 13,
118         RS_22_812_MODE_VOLT_DUTY        = 14,
119         RS_22_812_MODE_AMP_DUTY         = 15,
120         RS_22_812_MODE_WIDTH            = 16,
121         RS_22_812_MODE_VOLT_WIDTH       = 17,
122         RS_22_812_MODE_AMP_WIDTH        = 18,
123         RS_22_812_MODE_DIODE            = 19,
124         RS_22_812_MODE_CONT             = 20,
125         RS_22_812_MODE_HFE              = 21,
126         RS_22_812_MODE_LOGIC            = 22,
127         RS_22_812_MODE_DBM              = 23,
128         // RS_22_812_MODE_EF            = 24,
129         RS_22_812_MODE_TEMP             = 25,
130         RS_22_812_MODE_INVALID          = 26,
131 };
132
133 SR_PRIV gboolean rs_22_812_packet_valid(const struct rs_22_812_packet *rs_packet);
134
135 /* Private, per-device-instance driver context. */
136 struct dev_context {
137         uint64_t limit_samples;
138         struct sr_serial_dev_inst *serial;
139         char *serialcomm;
140
141         /* Opaque pointer passed in by the frontend. */
142         void *cb_data;
143
144         /* Runtime. */
145         uint64_t num_samples;
146         uint8_t buf[RS_DMM_BUFSIZE];
147         size_t bufoffset;
148         size_t buflen;
149 };
150
151 SR_PRIV int radioshack_dmm_receive_data(int fd, int revents, void *cb_data);
152
153 #endif