1 //
2 // Copyright 2017 Ettus Research, a National Instruments Company
3 //
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 //
6 
7 #pragma once
8 
9 #include "../ad937x_device_types.hpp"
10 #include "../adi/t_mykonos.h"
11 #include "mpm/ad937x/ad937x_ctrl_types.hpp"
12 #include <unordered_map>
13 #include <vector>
14 
15 // C++14 requires std::hash includes a specialization for enums, but gcc doesn't do that
16 // yet Remove this when that happens
17 namespace std {
18 template <>
19 struct hash<uhd::direction_t>
20 {
operator ()std::hash21     size_t operator()(const uhd::direction_t& x) const
22     {
23         return static_cast<std::size_t>(x);
24     }
25 };
26 
27 template <>
28 struct hash<mpm::ad937x::device::chain_t>
29 {
operator ()std::hash30     size_t operator()(const mpm::ad937x::device::chain_t& x) const
31     {
32         return static_cast<std::size_t>(x);
33     }
34 };
35 } // namespace std
36 
37 // collection of the 5 attributes that define the gain pins for a channel in Mykonos
38 struct ad937x_gain_ctrl_channel_t
39 {
40     uint8_t enable;
41     uint8_t inc_step;
42     uint8_t dec_step;
43     mykonosGpioSelect_t inc_pin;
44     mykonosGpioSelect_t dec_pin;
45 
46     ad937x_gain_ctrl_channel_t(mykonosGpioSelect_t inc_pin, mykonosGpioSelect_t dec_pin);
47 
48 private:
49     const static uint8_t DEFAULT_GAIN_STEP;
50     const static bool DEFAULT_ENABLE;
51 };
52 
53 // logically maps ad937x_gain_ctrl_channels by direction and channel number
54 struct ad937x_gain_ctrl_config_t
55 {
56     std::unordered_map<uhd::direction_t,
57         std::unordered_map<mpm::ad937x::device::chain_t, ad937x_gain_ctrl_channel_t>>
58         config;
59 
60     ad937x_gain_ctrl_config_t(mpm::ad937x::gpio::gain_pins_t gain_pins);
61 };
62