aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bladerf/bladerf_compat.h
blob: 2ad24be3d4c9d7335c5dbf5b54a00848eeefc64b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* -*- c++ -*- */
/*
 * Copyright 2017 Nuand LLC
 *
 * GNU Radio is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 *
 * GNU Radio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNU Radio; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */
#ifndef INCLUDED_BLADERF_COMPAT_H
#define INCLUDED_BLADERF_COMPAT_H

#if defined(LIBBLADERF_API_VERSION) && (LIBBLADERF_API_VERSION < 0x01080100)
    #warning Old libbladeRF detected: using compatibility workarounds.

    #define BLADERF_COMPATIBILITY

    /* New libbladeRF supports multiple channels, via various enums. */
    typedef bladerf_module bladerf_channel;
    #define BLADERF_CHANNEL_RX(ch) BLADERF_MODULE_RX
    #define BLADERF_CHANNEL_TX(ch) BLADERF_MODULE_TX
    #define BLADERF_CHANNEL_INVALID BLADERF_MODULE_INVALID

    typedef bladerf_module bladerf_channel_layout;
    #define BLADERF_RX_X1 BLADERF_MODULE_RX
    #define BLADERF_TX_X1 BLADERF_MODULE_TX
    #define BLADERF_RX_X2 BLADERF_MODULE_INVALID
    #define BLADERF_TX_X2 BLADERF_MODULE_INVALID

    typedef bladerf_module bladerf_direction;
    #define BLADERF_RX BLADERF_MODULE_RX
    #define BLADERF_TX BLADERF_MODULE_TX
    #define BLADERF_DIRECTION_MASK (0x1)

    /* Changed API calls */
    static
    int bladerf_get_frequency(struct bladerf *dev,
                              bladerf_channel ch,
                              uint64_t *freq) // was unsigned int *frequency
    {
        unsigned int f32 = 0;
        int status = bladerf_get_frequency(dev, ch, &f32);
        *freq = static_cast<uint64_t>(f32);
        return status;
    }

    static
    int bladerf_sync_tx(struct bladerf *dev,
                        void const *samples,  // was void *samples
                        unsigned int num_samples,
                        struct bladerf_metadata *metadata,
                        unsigned int timeout_ms)
    {
        void *s = const_cast<void *>(samples);
        return bladerf_sync_tx(dev, s, num_samples, metadata, timeout_ms);
    }

    /* Changed enums/defines */
    #define BLADERF_GAIN_DEFAULT BLADERF_GAIN_AUTOMATIC
    #define BLADERF_GAIN_MGC BLADERF_GAIN_MANUAL
    #define BLADERF_RX_MUX_BASEBAND BLADERF_RX_MUX_BASEBAND_LMS

    /* New functionality with no equivalent */
    #define BLADERF_LB_AD9361_BIST BLADERF_LB_NONE
    #define bladerf_get_board_name(name) "bladerf1"

#endif // libbladeRF < 1.8.1
#endif // INCLUDED_BLADERF_COMPAT_H