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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
//
// Copyright 2017 Ettus Research, a National Instruments Company
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#include "ad937x_gain_ctrl_config.hpp"
using namespace mpm::ad937x::gpio;
using namespace mpm::ad937x::device;
using namespace uhd;
const uint8_t ad937x_gain_ctrl_channel_t::DEFAULT_GAIN_STEP = 1;
const bool ad937x_gain_ctrl_channel_t::DEFAULT_ENABLE = 0;
// rx uses gain, tx uses attenuation
enum class pin_direction_t {
INCREASE,
DECREASE,
};
mykonosGpioSelect_t _convert_gain_pin(gain_pin_t pin)
{
switch (pin) {
case gain_pin_t::PIN0:
return MYKGPIO0;
case gain_pin_t::PIN1:
return MYKGPIO1;
case gain_pin_t::PIN2:
return MYKGPIO2;
case gain_pin_t::PIN3:
return MYKGPIO3;
case gain_pin_t::PIN4:
return MYKGPIO4;
case gain_pin_t::PIN5:
return MYKGPIO5;
case gain_pin_t::PIN6:
return MYKGPIO6;
case gain_pin_t::PIN7:
return MYKGPIO7;
case gain_pin_t::PIN8:
return MYKGPIO8;
case gain_pin_t::PIN9:
return MYKGPIO9;
case gain_pin_t::PIN10:
return MYKGPIO10;
case gain_pin_t::PIN11:
return MYKGPIO11;
case gain_pin_t::PIN12:
return MYKGPIO12;
case gain_pin_t::PIN13:
return MYKGPIO13;
case gain_pin_t::PIN14:
return MYKGPIO14;
case gain_pin_t::PIN15:
return MYKGPIO15;
case gain_pin_t::PIN16:
return MYKGPIO16;
case gain_pin_t::PIN17:
return MYKGPIO17;
case gain_pin_t::PIN18:
return MYKGPIO18;
default:
return MYKGPIONAN;
}
}
ad937x_gain_ctrl_channel_t::ad937x_gain_ctrl_channel_t(
mykonosGpioSelect_t inc_pin, mykonosGpioSelect_t dec_pin)
: enable(DEFAULT_ENABLE)
, inc_step(DEFAULT_GAIN_STEP)
, dec_step(DEFAULT_GAIN_STEP)
, inc_pin(inc_pin)
, dec_pin(dec_pin)
{
}
mykonosGpioSelect_t _get_gain_pin(direction_t direction,
chain_t chain,
pin_direction_t pin_direction,
const gain_pins_t& gain_pins)
{
switch (direction) {
case RX_DIRECTION:
switch (chain) {
case chain_t::ONE:
switch (pin_direction) {
case pin_direction_t::INCREASE:
return _convert_gain_pin(gain_pins.rx1_inc_gain_pin);
case pin_direction_t::DECREASE:
return _convert_gain_pin(gain_pins.rx1_dec_gain_pin);
}
case chain_t::TWO:
switch (pin_direction) {
case pin_direction_t::INCREASE:
return _convert_gain_pin(gain_pins.rx2_inc_gain_pin);
case pin_direction_t::DECREASE:
return _convert_gain_pin(gain_pins.rx2_dec_gain_pin);
}
}
// !!! TX is attenuation direction, so the pins are flipped !!!
case TX_DIRECTION:
switch (chain) {
case chain_t::ONE:
switch (pin_direction) {
case pin_direction_t::INCREASE:
return _convert_gain_pin(gain_pins.tx1_dec_gain_pin);
case pin_direction_t::DECREASE:
return _convert_gain_pin(gain_pins.tx1_inc_gain_pin);
}
case chain_t::TWO:
switch (pin_direction) {
case pin_direction_t::INCREASE:
return _convert_gain_pin(gain_pins.tx2_dec_gain_pin);
case pin_direction_t::DECREASE:
return _convert_gain_pin(gain_pins.tx2_inc_gain_pin);
}
}
default:
return MYKGPIONAN;
}
}
ad937x_gain_ctrl_config_t::ad937x_gain_ctrl_config_t(gain_pins_t gain_pins)
{
config.emplace(std::piecewise_construct,
std::forward_as_tuple(RX_DIRECTION),
std::forward_as_tuple());
config.emplace(std::piecewise_construct,
std::forward_as_tuple(TX_DIRECTION),
std::forward_as_tuple());
config.at(RX_DIRECTION)
.emplace(std::piecewise_construct,
std::forward_as_tuple(chain_t::ONE),
std::forward_as_tuple(
_get_gain_pin(
RX_DIRECTION, chain_t::ONE, pin_direction_t::INCREASE, gain_pins),
_get_gain_pin(
RX_DIRECTION, chain_t::ONE, pin_direction_t::DECREASE, gain_pins)));
config.at(RX_DIRECTION)
.emplace(std::piecewise_construct,
std::forward_as_tuple(chain_t::TWO),
std::forward_as_tuple(
_get_gain_pin(
RX_DIRECTION, chain_t::TWO, pin_direction_t::INCREASE, gain_pins),
_get_gain_pin(
RX_DIRECTION, chain_t::TWO, pin_direction_t::DECREASE, gain_pins)));
config.at(TX_DIRECTION)
.emplace(std::piecewise_construct,
std::forward_as_tuple(chain_t::ONE),
std::forward_as_tuple(
_get_gain_pin(
TX_DIRECTION, chain_t::ONE, pin_direction_t::INCREASE, gain_pins),
_get_gain_pin(
TX_DIRECTION, chain_t::ONE, pin_direction_t::DECREASE, gain_pins)));
config.at(TX_DIRECTION)
.emplace(std::piecewise_construct,
std::forward_as_tuple(chain_t::TWO),
std::forward_as_tuple(
_get_gain_pin(
TX_DIRECTION, chain_t::TWO, pin_direction_t::INCREASE, gain_pins),
_get_gain_pin(
TX_DIRECTION, chain_t::TWO, pin_direction_t::DECREASE, gain_pins)));
}
|