]> sigrok.org Git - libsigrok.git/blame - src/hardware/baylibre-acme/protocol.h
Build: Set local include directories in Makefile.am
[libsigrok.git] / src / hardware / baylibre-acme / protocol.h
CommitLineData
dfaee1de
BG
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2015 Bartosz Golaszewski <bgolaszewski@baylibre.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_BAYLIBRE_ACME_PROTOCOL_H
21#define LIBSIGROK_HARDWARE_BAYLIBRE_ACME_PROTOCOL_H
22
23#include <stdint.h>
24#include <glib.h>
391e23a9 25#include <unistd.h>
c1aae900 26#include <libsigrok/libsigrok.h>
dfaee1de
BG
27#include "libsigrok-internal.h"
28
29#define LOG_PREFIX "baylibre-acme"
30
6b80b80d
BG
31/* We support up to 8 energy/temperature probes. */
32#define MAX_PROBES 8
33
34/*
35 * Temperature probes can be connected to the last four ports on the
36 * ACME cape. When scanning, first look for temperature probes starting
37 * from this index.
38 */
39#define TEMP_PRB_START_INDEX 4
40
41#define ENRG_PROBE_NAME "ina226"
42#define TEMP_PROBE_NAME "tmp435"
43
44/* For the user we number the probes starting from 1. */
391e23a9 45#define PROBE_NUM(n) ((n) + 1)
6b80b80d
BG
46
47enum probe_type {
48 PROBE_ENRG = 1,
49 PROBE_TEMP,
50};
51
52enum channel_type {
53 ENRG_PWR = 1,
54 ENRG_CURR,
55 ENRG_VOL,
56 TEMP_IN,
57 TEMP_OUT,
58};
59
dfaee1de
BG
60/** Private, per-device-instance driver context. */
61struct dev_context {
6b80b80d
BG
62 uint64_t samplerate;
63 uint64_t limit_samples;
64 uint64_t limit_msec;
dfaee1de 65
6b80b80d
BG
66 uint32_t num_channels;
67 uint64_t samples_read;
a0648b1a 68 uint64_t samples_missed;
6b80b80d
BG
69 int64_t start_time;
70 int64_t last_sample_fin;
a0648b1a 71 int timer_fd;
6b80b80d
BG
72 GIOChannel *channel;
73};
dfaee1de 74
6b80b80d
BG
75SR_PRIV uint8_t bl_acme_get_enrg_addr(int index);
76SR_PRIV uint8_t bl_acme_get_temp_addr(int index);
dfaee1de 77
6b80b80d 78SR_PRIV gboolean bl_acme_is_sane(void);
dfaee1de 79
6b80b80d
BG
80SR_PRIV gboolean bl_acme_detect_probe(unsigned int addr,
81 int prb_num, const char *prb_name);
82SR_PRIV gboolean bl_acme_register_probe(struct sr_dev_inst *sdi, int type,
83 unsigned int addr, int prb_num);
dfaee1de 84
1fe04eb8
BG
85SR_PRIV int bl_acme_get_probe_type(const struct sr_channel_group *cg);
86SR_PRIV int bl_acme_probe_has_pws(const struct sr_channel_group *cg);
87
7c91c22a
BG
88SR_PRIV void bl_acme_maybe_set_update_interval(const struct sr_dev_inst *sdi,
89 uint64_t samplerate);
90
61f2b7f7
BG
91SR_PRIV int bl_acme_get_shunt(const struct sr_channel_group *cg,
92 uint64_t *shunt);
93SR_PRIV int bl_acme_set_shunt(const struct sr_channel_group *cg,
94 uint64_t shunt);
740ad48a
BG
95SR_PRIV int bl_acme_read_power_state(const struct sr_channel_group *cg,
96 gboolean *off);
97SR_PRIV int bl_acme_set_power_off(const struct sr_channel_group *cg,
98 gboolean off);
61f2b7f7 99
6b80b80d 100SR_PRIV int bl_acme_receive_data(int fd, int revents, void *cb_data);
dfaee1de 101
4e88b86c
DL
102SR_PRIV int bl_acme_open_channel(struct sr_channel *ch);
103
104SR_PRIV void bl_acme_close_channel(struct sr_channel *ch);
dfaee1de 105#endif